changeset 4631:e3afa670e484

demandimport: fix issue579 and add a test fix suggested by Brendan
author Matt Mackall <mpm@selenic.com>
date Mon, 18 Jun 2007 19:43:26 -0500
parents e6d105a51ec7
children 8d46056960ab
files mercurial/demandimport.py tests/test-demandimport tests/test-demandimport.out
diffstat 3 files changed, 70 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/demandimport.py	Mon Jun 18 17:49:56 2007 -0500
+++ b/mercurial/demandimport.py	Mon Jun 18 19:43:26 2007 -0500
@@ -61,7 +61,10 @@
             if locals and locals.get(head) == self:
                 locals[head] = mod
             object.__setattr__(self, "_module", mod)
+
     def __repr__(self):
+        if self._module:
+            return "<proxied module '%s'>" % self._data[0]
         return "<unloaded module '%s'>" % self._data[0]
     def __call__(self, *args, **kwargs):
         raise TypeError("'unloaded module' object is not callable")
@@ -102,7 +105,7 @@
         for x in fromlist:
             # set requested submodules for demand load
             if not(hasattr(mod, x)):
-                setattr(mod, x, _demandmod(x, mod.__dict__, mod.__dict__))
+                setattr(mod, x, _demandmod(x, mod.__dict__, locals))
         return mod
 
 ignore = ['_hashlib', '_xmlplus', 'fcntl', 'win32com.gen_py']
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-demandimport	Mon Jun 18 19:43:26 2007 -0500
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+
+from mercurial import demandimport
+demandimport.enable()
+
+import re
+
+rsub = re.sub
+def f(obj):
+    l = repr(obj)
+    l = rsub("0x[0-9a-f]+", "0x?", l)
+    l = rsub("from '.*'", "from '?'", l)
+    return l
+
+import os
+
+print "os =", f(os)
+print "os.system =", f(os.system)
+print "os =", f(os)
+
+import mercurial.version
+
+print "mercurial.version =", f(mercurial.version)
+print "mercurial.version.get_version =", f(mercurial.version.get_version)
+print "mercurial.version =", f(mercurial.version)
+print "mercurial =", f(mercurial)
+
+from mercurial import util
+
+print "util =", f(util)
+print "util.system =", f(util.system)
+print "util =", f(util)
+print "util.system =", f(util.system)
+
+import re as fred
+print "fred =", f(fred)
+
+import sys as re
+print "re =", f(re)
+
+print "fred =", f(fred)
+print "fred.sub =", f(fred.sub)
+print "fred =", f(fred)
+
+print "re =", f(re)
+print "re.stdout =", f(re.stdout)
+print "re =", f(re)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-demandimport.out	Mon Jun 18 19:43:26 2007 -0500
@@ -0,0 +1,19 @@
+os = <unloaded module 'os'>
+os.system = <built-in function system>
+os = <module 'os' from '?'>
+mercurial.version = <unloaded module 'version'>
+mercurial.version.get_version = <function get_version at 0x?>
+mercurial.version = <module 'mercurial.version' from '?'>
+mercurial = <module 'mercurial' from '?'>
+util = <unloaded module 'util'>
+util.system = <function system at 0x?>
+util = <module 'mercurial.util' from '?'>
+util.system = <function system at 0x?>
+fred = <unloaded module 're'>
+re = <unloaded module 'sys'>
+fred = <unloaded module 're'>
+fred.sub = <function sub at 0x?>
+fred = <proxied module 're'>
+re = <unloaded module 'sys'>
+re.stdout = <open file '<stdout>', mode 'w' at 0x?>
+re = <proxied module 'sys'>