Re: [PATCH 3 of 3 v3] demandimport: reject contextlib._GeneratorContextManager on Py < 3.2
On Wed, 21 Sep 2016 19:09:34 +, timeless wrote: > # HG changeset patch > # User timeless> # Date 1474429683 0 > # Wed Sep 21 03:48:03 2016 + > # Node ID 0070696439eab002f6dd32bcb40eb671daff800a > # Parent adb54fd7d90f0ca607432ed7ae884da55ec427de > # Available At https://bitbucket.org/timeless/mercurial-crew > # hg pull https://bitbucket.org/timeless/mercurial-crew -r > 0070696439ea > demandimport: reject contextlib._GeneratorContextManager on Py < 3.2 > > decorator expects: > from contextlib import _GeneratorContextManager > to throw an exception on python < 3.2 (issue5373). > > We tell demandimport to throw it. > > diff -r adb54fd7d90f -r 0070696439ea mercurial/demandimport.py > --- a/mercurial/demandimport.py Wed Sep 21 18:58:54 2016 + > +++ b/mercurial/demandimport.py Wed Sep 21 03:48:03 2016 + > @@ -313,6 +313,12 @@ > if os.name != 'nt': > reject('distutils', 'msvc9compiler', ImportError, 'No module named > _winreg') > > +# decorator imported by ipython from pygments does an import which isn't > +# friendly to demandimport. > +if sys.version_info[0] < 3 or sys.version_info[1] < 2: > +reject('contextlib', '_GeneratorContextManager', > + ImportError, 'cannot import name _GeneratorContextManager') I'm not a fan of duplicating knowledge about module internals unless there's a measurable win. We could break the current "ignore" list down to fine-tuned "rejects" rules, but that would end with bloated set of rules we wouldn't want to maintain. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 3 of 3 v3] demandimport: reject contextlib._GeneratorContextManager on Py < 3.2
Siddharth Agarwal wrote: > As a general thing I don't think we should be spending time trying to fix > this implementation of demandimport on Python 3 at all. This isn't really about python3, it's just about foreign code that expects a certain object to look a certain way, but because of demandimport it gets a demandimport object stub instead of an exception -- in python3 it would have at least gotten a stub for a real object. -- I don't know if the code works in py3 but that's a different adventure, and I'm happy to let a python3 demandimport solution worry about it. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 3 of 3 v3] demandimport: reject contextlib._GeneratorContextManager on Py < 3.2
On 9/21/16 12:09, timeless wrote: # HG changeset patch # User timeless# Date 1474429683 0 # Wed Sep 21 03:48:03 2016 + # Node ID 0070696439eab002f6dd32bcb40eb671daff800a # Parent adb54fd7d90f0ca607432ed7ae884da55ec427de # Available At https://bitbucket.org/timeless/mercurial-crew # hg pull https://bitbucket.org/timeless/mercurial-crew -r 0070696439ea demandimport: reject contextlib._GeneratorContextManager on Py < 3.2 As a general thing I don't think we should be spending time trying to fix this implementation of demandimport on Python 3 at all. I would much rather we use an implementation based on the new importlib stuff, like the one I sent to the list a while back. (Hopefully I can get it in during the sprint.) - Siddharth decorator expects: from contextlib import _GeneratorContextManager to throw an exception on python < 3.2 (issue5373). We tell demandimport to throw it. diff -r adb54fd7d90f -r 0070696439ea mercurial/demandimport.py --- a/mercurial/demandimport.py Wed Sep 21 18:58:54 2016 + +++ b/mercurial/demandimport.py Wed Sep 21 03:48:03 2016 + @@ -313,6 +313,12 @@ if os.name != 'nt': reject('distutils', 'msvc9compiler', ImportError, 'No module named _winreg') +# decorator imported by ipython from pygments does an import which isn't +# friendly to demandimport. +if sys.version_info[0] < 3 or sys.version_info[1] < 2: +reject('contextlib', '_GeneratorContextManager', + ImportError, 'cannot import name _GeneratorContextManager') + def isenabled(): return builtins.__import__ == _demandimport diff -r adb54fd7d90f -r 0070696439ea tests/test-demandimport.py --- a/tests/test-demandimport.pyWed Sep 21 18:58:54 2016 + +++ b/tests/test-demandimport.pyWed Sep 21 03:48:03 2016 + @@ -71,6 +71,15 @@ except ImportError: pass +if sys.version_info[0] < 3 or sys.version_info[1] < 2: +try: +from contextlib import _GeneratorContextManager +print('contextlib._GeneratorContextManager needs to be an ' + 'immediate importerror on python <3.2') +_GeneratorContextManager.__doc__ +except ImportError: +pass + demandimport.disable() os.environ['HGDEMANDIMPORT'] = 'disable' # this enable call should not actually enable demandimport! ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel