[Python-Dev] decorator support (original) (raw)
Josiah Carlson jcarlson at uci.edu
Mon Sep 6 00:42:56 CEST 2004
- Previous message: [Python-Dev] decorator support
- Next message: [Python-Dev] Alternative placeholder delimiters for PEP 292
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] decorator support
- Next message: [Python-Dev] Alternative placeholder delimiters for PEP 292
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]