Patchwork [Bug,4029] New: demandimport doesn't honor absolute_import

mail settings
Date Sept. 6, 2013, 2:22 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/2387/
State Not Applicable
Headers show

Comments - Sept. 6, 2013, 2:22 a.m.

          Priority: normal
            Bug ID: 4029
           Summary: demandimport doesn't honor absolute_import
          Severity: bug
    Classification: Unclassified
                OS: Windows
          Hardware: PC
            Status: UNCONFIRMED
           Version: 2.7.1
         Component: Mercurial
           Product: Mercurial

it became apparent that the demand import machinery doesn't honor the
'absolute_import' directive. If a relative import is present, it is given
preference even if the module author has indicated absolute_import from

I believe the fix is pretty straightforward. I've tested this against the
reported issue and it fixes the failure (and imports the correct module from
the root namespace).

Please consider committing this patch. Thanks.


diff -r 1d07bf106c2a mercurial/
--- a/mercurial/    Wed Sep 04 18:42:55 2013 -0700
+++ b/mercurial/    Thu Sep 05 22:11:20 2013 -0400
@@ -55,7 +55,9 @@ 
     def _load(self):
         if not self._module:
             head, globals, locals, after = self._data
-            mod = _origimport(head, globals, locals)
+            if 'absolute_import' in locals:
+                level = 0
+            mod = _origimport(head, globals, locals, [], level)
             # load submodules
             def subload(mod, p):
                 h, t = p, None