> newf.__doc__ = oldf.__doc__ # copy the docstring > newf.__dict__.update(oldf.__dict__) # copy attributes > newf.__name__ = oldf.__name__ # keep the name (new in Py2.4) > newf.__undecorated__ = oldf # [XX NEW] ptr to undecorated obj If one were to consider function decorators as a type of 'subclass' of a particular function, that is, post-decoration a function inherits from the pre-decoration version of the function, we could, with a single attribute (like __undecorated__ or __proxyfor__ as suggested) and proper introspection tools, do iterative attribute lookups similar to the way that it is already done with classes (without diamond-inheritance). That is, one wouldn't need to copy __doc__, __name__, and __dict__ from a decorated function, one would get access to them automatically. In current Python, what I am saying would be equivalent to... def foo(arg): pass t = foo foo = arbitrary_decorator(foo) foo.__proxyfor__ = t del t It would be some 'behind-the-scenes-magic', but I think it may be the right amount and kind of magic. - Josiah
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4