Patchwork [2,of,4] demandimport: drop hack for old Pythons which had no level argument

login
register
mail settings
Submitter Yuya Nishihara
Date July 16, 2017, 2:41 p.m.
Message ID <10093dbe4b0785678511.1500216109@mimosa>
Download mbox | patch
Permalink /patch/22439/
State Accepted
Headers show

Comments

Yuya Nishihara - July 16, 2017, 2:41 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1500192992 -32400
#      Sun Jul 16 17:16:32 2017 +0900
# Node ID 10093dbe4b0785678511fc4e7d3088746019742c
# Parent  5a71b2b7e12f057175e293daf74c7dee897f3008
demandimport: drop hack for old Pythons which had no level argument

_import() was added by 868282fa29d8, but it is identical to _origimport()
now.

Patch

diff --git a/hgdemandimport/demandimportpy2.py b/hgdemandimport/demandimportpy2.py
--- a/hgdemandimport/demandimportpy2.py
+++ b/hgdemandimport/demandimportpy2.py
@@ -46,7 +46,6 @@  nothing = object()
 level = -1
 if sys.version_info[0] >= 3:
     level = 0
-_import = _origimport
 
 def _hgextimport(importfunc, name, globals, *args, **kwargs):
     try:
@@ -99,7 +98,7 @@  class _demandmod(object):
     def _load(self):
         if not self._module:
             head, globals, locals, after, level, modrefs = self._data
-            mod = _hgextimport(_import, head, globals, locals, None, level)
+            mod = _hgextimport(_origimport, head, globals, locals, None, level)
             if mod is self:
                 # In this case, _hgextimport() above should imply
                 # _demandimport(). Otherwise, _hgextimport() never
@@ -176,14 +175,14 @@  class _demandmod(object):
 def _demandimport(name, globals=None, locals=None, fromlist=None, level=level):
     if locals is None or name in ignore or fromlist == ('*',):
         # these cases we can't really delay
-        return _hgextimport(_import, name, globals, locals, fromlist, level)
+        return _hgextimport(_origimport, name, globals, locals, fromlist, level)
     elif not fromlist:
         # import a [as b]
         if '.' in name: # a.b
             base, rest = name.split('.', 1)
             # email.__init__ loading email.mime
             if globals and globals.get('__name__', None) == base:
-                return _import(name, globals, locals, fromlist, level)
+                return _origimport(name, globals, locals, fromlist, level)
             # if a is already demand-loaded, add b to its submodule list
             if base in locals:
                 if isinstance(locals[base], _demandmod):
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -1672,7 +1672,7 @@  Even though the extension fails during u
     File "*/hgdemandimport/demandimportpy2.py", line *, in __getattr__ (glob)
       self._load()
     File "*/hgdemandimport/demandimportpy2.py", line *, in _load (glob)
-      mod = _hgextimport(_import, head, globals, locals, None, level)
+      mod = _hgextimport(_origimport, head, globals, locals, None, level)
     File "*/hgdemandimport/demandimportpy2.py", line *, in _hgextimport (glob)
       return importfunc(name, globals, *args, **kwargs)
   ImportError: No module named bdiff