##// END OF EJS Templates
demandimport: drop hack for old Pythons which had no level argument...
Yuya Nishihara -
r33529:ded3ebae default
parent child Browse files
Show More
@@ -46,7 +46,6 b' nothing = object()'
46 level = -1
46 level = -1
47 if sys.version_info[0] >= 3:
47 if sys.version_info[0] >= 3:
48 level = 0
48 level = 0
49 _import = _origimport
50
49
51 def _hgextimport(importfunc, name, globals, *args, **kwargs):
50 def _hgextimport(importfunc, name, globals, *args, **kwargs):
52 try:
51 try:
@@ -99,7 +98,7 b' class _demandmod(object):'
99 def _load(self):
98 def _load(self):
100 if not self._module:
99 if not self._module:
101 head, globals, locals, after, level, modrefs = self._data
100 head, globals, locals, after, level, modrefs = self._data
102 mod = _hgextimport(_import, head, globals, locals, None, level)
101 mod = _hgextimport(_origimport, head, globals, locals, None, level)
103 if mod is self:
102 if mod is self:
104 # In this case, _hgextimport() above should imply
103 # In this case, _hgextimport() above should imply
105 # _demandimport(). Otherwise, _hgextimport() never
104 # _demandimport(). Otherwise, _hgextimport() never
@@ -176,14 +175,14 b' class _demandmod(object):'
176 def _demandimport(name, globals=None, locals=None, fromlist=None, level=level):
175 def _demandimport(name, globals=None, locals=None, fromlist=None, level=level):
177 if locals is None or name in ignore or fromlist == ('*',):
176 if locals is None or name in ignore or fromlist == ('*',):
178 # these cases we can't really delay
177 # these cases we can't really delay
179 return _hgextimport(_import, name, globals, locals, fromlist, level)
178 return _hgextimport(_origimport, name, globals, locals, fromlist, level)
180 elif not fromlist:
179 elif not fromlist:
181 # import a [as b]
180 # import a [as b]
182 if '.' in name: # a.b
181 if '.' in name: # a.b
183 base, rest = name.split('.', 1)
182 base, rest = name.split('.', 1)
184 # email.__init__ loading email.mime
183 # email.__init__ loading email.mime
185 if globals and globals.get('__name__', None) == base:
184 if globals and globals.get('__name__', None) == base:
186 return _import(name, globals, locals, fromlist, level)
185 return _origimport(name, globals, locals, fromlist, level)
187 # if a is already demand-loaded, add b to its submodule list
186 # if a is already demand-loaded, add b to its submodule list
188 if base in locals:
187 if base in locals:
189 if isinstance(locals[base], _demandmod):
188 if isinstance(locals[base], _demandmod):
@@ -1672,7 +1672,7 b' Even though the extension fails during u'
1672 File "*/hgdemandimport/demandimportpy2.py", line *, in __getattr__ (glob)
1672 File "*/hgdemandimport/demandimportpy2.py", line *, in __getattr__ (glob)
1673 self._load()
1673 self._load()
1674 File "*/hgdemandimport/demandimportpy2.py", line *, in _load (glob)
1674 File "*/hgdemandimport/demandimportpy2.py", line *, in _load (glob)
1675 mod = _hgextimport(_import, head, globals, locals, None, level)
1675 mod = _hgextimport(_origimport, head, globals, locals, None, level)
1676 File "*/hgdemandimport/demandimportpy2.py", line *, in _hgextimport (glob)
1676 File "*/hgdemandimport/demandimportpy2.py", line *, in _hgextimport (glob)
1677 return importfunc(name, globals, *args, **kwargs)
1677 return importfunc(name, globals, *args, **kwargs)
1678 ImportError: No module named bdiff
1678 ImportError: No module named bdiff
General Comments 0
You need to be logged in to leave comments. Login now