Re: [PATCH 5 of 5] demandimport: reject contextlib._GeneratorContextManager on Py < 3.2
Yuya Nishihara wrote: > Can't we simply ignore 'contextlib' ? I had a patch that did that. It felt gross (it clearly wasn't very elegant) > Since contextlib is imported by demandimport.py, there's no benefit to delay > importing contextlib. So, demandimport could just return a given module if it's already loaded w/o wrapping things, but it's possible for a module to be loaded w/o its submodules being loaded. We don't want to automatically load all submodules (that would more or less bypass demandimport, and thus defeat its purpose). I think that other modules have similarly unfriendly code, and that it thus makes sense to offer this feature. After looking through our list of ignores, I think that it should be possible to make distutils.msvc9compiler work with my general approach (although the specific implementation I have in v1 and v2 doesn't work, so I'll need a v3). ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 5 of 5] demandimport: reject contextlib._GeneratorContextManager on Py < 3.2
On Wed, 21 Sep 2016 03:59:35 +, timeless wrote: > # HG changeset patch > # User timeless> # Date 1474429683 0 > # Wed Sep 21 03:48:03 2016 + > # Node ID e07c3d398573f74a2e382deb06462bdc15ed437f > # Parent 894cc47eb82a85d167f5717c9fe0a31392e5bb97 > # Available At https://bitbucket.org/timeless/mercurial-crew > # hg pull https://bitbucket.org/timeless/mercurial-crew -r > e07c3d398573 > demandimport: reject contextlib._GeneratorContextManager on Py < 3.2 > > issue5373 > > diff -r 894cc47eb82a -r e07c3d398573 mercurial/demandimport.py > --- a/mercurial/demandimport.py Wed Sep 21 03:47:35 2016 + > +++ b/mercurial/demandimport.py Wed Sep 21 03:48:03 2016 + > @@ -306,6 +306,13 @@ > if not mod in rejects: > rejects[mod] = {} > rejects[mod][prop] = [cls, msg] > + > +# 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') Can't we simply ignore 'contextlib' ? Since contextlib is imported by demandimport.py, there's no benefit to delay importing contextlib. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
[PATCH 5 of 5] demandimport: reject contextlib._GeneratorContextManager on Py < 3.2
# HG changeset patch # User timeless# Date 1474429683 0 # Wed Sep 21 03:48:03 2016 + # Node ID e07c3d398573f74a2e382deb06462bdc15ed437f # Parent 894cc47eb82a85d167f5717c9fe0a31392e5bb97 # Available At https://bitbucket.org/timeless/mercurial-crew # hg pull https://bitbucket.org/timeless/mercurial-crew -r e07c3d398573 demandimport: reject contextlib._GeneratorContextManager on Py < 3.2 issue5373 diff -r 894cc47eb82a -r e07c3d398573 mercurial/demandimport.py --- a/mercurial/demandimport.py Wed Sep 21 03:47:35 2016 + +++ b/mercurial/demandimport.py Wed Sep 21 03:48:03 2016 + @@ -306,6 +306,13 @@ if not mod in rejects: rejects[mod] = {} rejects[mod][prop] = [cls, msg] + +# 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 894cc47eb82a -r e07c3d398573 tests/test-demandimport.py --- a/tests/test-demandimport.pyWed Sep 21 03:47:35 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