# HG changeset patch # User Matt Mackall # Date 1182213806 18000 # Node ID e3afa670e48495648903017253b75d2a494fbf5e # Parent e6d105a51ec755ca6b75798c9bcd4457f02e3804 demandimport: fix issue579 and add a test fix suggested by Brendan diff --git a/mercurial/demandimport.py b/mercurial/demandimport.py --- a/mercurial/demandimport.py +++ b/mercurial/demandimport.py @@ -61,7 +61,10 @@ class _demandmod(object): if locals and locals.get(head) == self: locals[head] = mod object.__setattr__(self, "_module", mod) + def __repr__(self): + if self._module: + return "" % self._data[0] return "" % self._data[0] def __call__(self, *args, **kwargs): raise TypeError("'unloaded module' object is not callable") @@ -102,7 +105,7 @@ def _demandimport(name, globals=None, lo 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'] diff --git a/tests/test-demandimport b/tests/test-demandimport new file mode 100755 --- /dev/null +++ b/tests/test-demandimport @@ -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) diff --git a/tests/test-demandimport.out b/tests/test-demandimport.out new file mode 100644 --- /dev/null +++ b/tests/test-demandimport.out @@ -0,0 +1,19 @@ +os = +os.system = +os = +mercurial.version = +mercurial.version.get_version = +mercurial.version = +mercurial = +util = +util.system = +util = +util.system = +fred = +re = +fred = +fred.sub = +fred = +re = +re.stdout = ', mode 'w' at 0x?> +re =