changeset 32485:252d2260c74e

demandimport: look for 'mod' suffix as alternative name for module reference It's widely used in our codebase.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 28 Apr 2017 23:46:16 +0900
parents 63365e9621d6
children 91a2ec8e7fa0
files hgdemandimport/demandimportpy2.py tests/test-demandimport.py tests/test-demandimport.py.out
diffstat 3 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgdemandimport/demandimportpy2.py	Mon May 01 14:26:56 2017 +0900
+++ b/hgdemandimport/demandimportpy2.py	Fri Apr 28 23:46:16 2017 +0900
@@ -132,8 +132,11 @@
                 subload(mod, x)
 
             # Replace references to this proxy instance with the actual module.
-            if locals and locals.get(head) is self:
-                locals[head] = mod
+            if locals:
+                if locals.get(head) is self:
+                    locals[head] = mod
+                elif locals.get(head + r'mod') is self:
+                    locals[head + r'mod'] = mod
 
             for modname in modrefs:
                 modref = sys.modules.get(modname, None)
--- a/tests/test-demandimport.py	Mon May 01 14:26:56 2017 +0900
+++ b/tests/test-demandimport.py	Fri Apr 28 23:46:16 2017 +0900
@@ -52,6 +52,9 @@
 import re as fred
 print("fred =", f(fred))
 
+import re as remod
+print("remod =", f(remod))
+
 import sys as re
 print("re =", f(re))
 
@@ -59,6 +62,9 @@
 print("fred.sub =", f(fred.sub))
 print("fred =", f(fred))
 
+remod.escape  # use remod
+print("remod =", f(remod))
+
 print("re =", f(re))
 print("re.stderr =", f(re.stderr))
 print("re =", f(re))
--- a/tests/test-demandimport.py.out	Mon May 01 14:26:56 2017 +0900
+++ b/tests/test-demandimport.py.out	Fri Apr 28 23:46:16 2017 +0900
@@ -9,10 +9,12 @@
 hgweb_mod = <unloaded module 'hgweb_mod'>
 hgweb = <module 'mercurial.hgweb' from '?'>
 fred = <unloaded module 're'>
+remod = <unloaded module 're'>
 re = <unloaded module 'sys'>
 fred = <unloaded module 're'>
 fred.sub = <function sub at 0x?>
 fred = <proxied module 're'>
+remod = <module 're' from '?'>
 re = <unloaded module 'sys'>
 re.stderr = <open file '<whatever>', mode 'w' at 0x?>
 re = <proxied module 'sys'>