Mercurial > hg-stable
changeset 13082:4db5bfea1b07
demandimport: change default for level from None to -1
The Python default for this function is -1, indicating both relative
and absolute imports should be used.[1] Previously, we relied on the
Python VM not passing level when such semantics were
requisted. This is not the case for PyPy, however, where a level of -1
is always passed to __import__.
[1] <http://docs.python.org/library/functions.html#__import__>
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Wed, 01 Dec 2010 21:46:08 +0100 |
parents | 79184986658c |
children | c0290fc6b486 |
files | mercurial/demandimport.py |
diffstat | 1 files changed, 7 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/demandimport.py Wed Dec 01 21:46:08 2010 +0100 +++ b/mercurial/demandimport.py Wed Dec 01 21:46:08 2010 +0100 @@ -78,10 +78,10 @@ self._load() setattr(self._module, attr, val) -def _demandimport(name, globals=None, locals=None, fromlist=None, level=None): +def _demandimport(name, globals=None, locals=None, fromlist=None, level=-1): if not locals or name in ignore or fromlist == ('*',): # these cases we can't really delay - if level is None: + if level == -1: return _origimport(name, globals, locals, fromlist) else: return _origimport(name, globals, locals, fromlist, level) @@ -91,7 +91,10 @@ base, rest = name.split('.', 1) # email.__init__ loading email.mime if globals and globals.get('__name__', None) == base: - return _origimport(name, globals, locals, fromlist) + if level != -1: + return _origimport(name, globals, locals, fromlist, level) + else: + return _origimport(name, globals, locals, fromlist) # if a is already demand-loaded, add b to its submodule list if base in locals: if isinstance(locals[base], _demandmod): @@ -99,7 +102,7 @@ return locals[base] return _demandmod(name, globals, locals) else: - if level is not None: + if level != -1: # from . import b,c,d or from .a import b,c,d return _origimport(name, globals, locals, fromlist, level) # from a import b,c,d