Mercurial > hg
diff 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 |
line wrap: on
line diff
--- a/hgdemandimport/demandimportpy2.py Fri Apr 28 23:46:16 2017 +0900 +++ b/hgdemandimport/demandimportpy2.py Fri Apr 28 00:01:22 2017 +0900 @@ -153,9 +153,7 @@ def __call__(self, *args, **kwargs): raise TypeError("%s object is not callable" % repr(self)) - def __getattribute__(self, attr): - if attr in ('_data', '_extend', '_load', '_module', '_addref'): - return object.__getattribute__(self, attr) + def __getattr__(self, attr): self._load() return getattr(self._module, attr) @@ -163,6 +161,16 @@ self._load() setattr(self._module, attr, val) + @property + def __dict__(self): + self._load() + return self._module.__dict__ + + @property + def __doc__(self): + self._load() + return self._module.__doc__ + _pypy = '__pypy__' in sys.builtin_module_names def _demandimport(name, globals=None, locals=None, fromlist=None, level=level):