Show More
@@ -153,9 +153,7 b' class _demandmod(object):' | |||||
153 | def __call__(self, *args, **kwargs): |
|
153 | def __call__(self, *args, **kwargs): | |
154 | raise TypeError("%s object is not callable" % repr(self)) |
|
154 | raise TypeError("%s object is not callable" % repr(self)) | |
155 |
|
155 | |||
156 |
def __getattr |
|
156 | def __getattr__(self, attr): | |
157 | if attr in ('_data', '_extend', '_load', '_module', '_addref'): |
|
|||
158 | return object.__getattribute__(self, attr) |
|
|||
159 | self._load() |
|
157 | self._load() | |
160 | return getattr(self._module, attr) |
|
158 | return getattr(self._module, attr) | |
161 |
|
159 | |||
@@ -163,6 +161,16 b' class _demandmod(object):' | |||||
163 | self._load() |
|
161 | self._load() | |
164 | setattr(self._module, attr, val) |
|
162 | setattr(self._module, attr, val) | |
165 |
|
163 | |||
|
164 | @property | |||
|
165 | def __dict__(self): | |||
|
166 | self._load() | |||
|
167 | return self._module.__dict__ | |||
|
168 | ||||
|
169 | @property | |||
|
170 | def __doc__(self): | |||
|
171 | self._load() | |||
|
172 | return self._module.__doc__ | |||
|
173 | ||||
166 | _pypy = '__pypy__' in sys.builtin_module_names |
|
174 | _pypy = '__pypy__' in sys.builtin_module_names | |
167 |
|
175 | |||
168 | def _demandimport(name, globals=None, locals=None, fromlist=None, level=level): |
|
176 | def _demandimport(name, globals=None, locals=None, fromlist=None, level=level): |
@@ -69,6 +69,17 b' print("re =", f(re))' | |||||
69 | print("re.stderr =", f(re.stderr)) |
|
69 | print("re.stderr =", f(re.stderr)) | |
70 | print("re =", f(re)) |
|
70 | print("re =", f(re)) | |
71 |
|
71 | |||
|
72 | # Test access to special attributes through demandmod proxy | |||
|
73 | from mercurial import pvec as pvecproxy | |||
|
74 | print("pvecproxy =", f(pvecproxy)) | |||
|
75 | print("pvecproxy.__doc__ = %r" | |||
|
76 | % (' '.join(pvecproxy.__doc__.split()[:3]) + ' ...')) | |||
|
77 | print("pvecproxy.__name__ = %r" % pvecproxy.__name__) | |||
|
78 | # __name__ must be accessible via __dict__ so the relative imports can be | |||
|
79 | # resolved | |||
|
80 | print("pvecproxy.__dict__['__name__'] = %r" % pvecproxy.__dict__['__name__']) | |||
|
81 | print("pvecproxy =", f(pvecproxy)) | |||
|
82 | ||||
72 | import contextlib |
|
83 | import contextlib | |
73 | print("contextlib =", f(contextlib)) |
|
84 | print("contextlib =", f(contextlib)) | |
74 | try: |
|
85 | try: |
@@ -18,6 +18,11 b" remod = <module 're' from '?'>" | |||||
18 | re = <unloaded module 'sys'> |
|
18 | re = <unloaded module 'sys'> | |
19 | re.stderr = <open file '<whatever>', mode 'w' at 0x?> |
|
19 | re.stderr = <open file '<whatever>', mode 'w' at 0x?> | |
20 | re = <proxied module 'sys'> |
|
20 | re = <proxied module 'sys'> | |
|
21 | pvecproxy = <unloaded module 'pvec'> | |||
|
22 | pvecproxy.__doc__ = 'A "pvec" is ...' | |||
|
23 | pvecproxy.__name__ = 'mercurial.pvec' | |||
|
24 | pvecproxy.__dict__['__name__'] = 'mercurial.pvec' | |||
|
25 | pvecproxy = <proxied module 'pvec'> | |||
21 | contextlib = <unloaded module 'contextlib'> |
|
26 | contextlib = <unloaded module 'contextlib'> | |
22 | contextlib.unknownattr = ImportError: cannot import name unknownattr |
|
27 | contextlib.unknownattr = ImportError: cannot import name unknownattr | |
23 | __import__('contextlib', ..., ['unknownattr']) = <module 'contextlib' from '?'> |
|
28 | __import__('contextlib', ..., ['unknownattr']) = <module 'contextlib' from '?'> |
General Comments 0
You need to be logged in to leave comments.
Login now