Mercurial > hg
comparison hgdemandimport/demandimportpy2.py @ 32448:91a2ec8e7fa0
demandimport: stop overriding __getattribute__()
Proxy __dict__ and __doc__ explicitly instead.
I'm not sure which is less evil, but this seems slightly simpler than hooking
all attribute accesses.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 28 Apr 2017 00:01:22 +0900 |
parents | 252d2260c74e |
children | ded3ebae8779 |
comparison
equal
deleted
inserted
replaced
32447:252d2260c74e | 32448:91a2ec8e7fa0 |
---|---|
151 return "<unloaded module '%s'>" % self._data[0] | 151 return "<unloaded module '%s'>" % self._data[0] |
152 | 152 |
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 __getattribute__(self, attr): | 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 |
162 def __setattr__(self, attr, val): | 160 def __setattr__(self, attr, val): |
163 self._load() | 161 self._load() |
164 setattr(self._module, attr, val) | 162 setattr(self._module, attr, val) |
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__ | |
165 | 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): |
169 if locals is None or name in ignore or fromlist == ('*',): | 177 if locals is None or name in ignore or fromlist == ('*',): |