[Python-Dev] Re: decorators and 2.4
Armin Rigo
arigo at tunes.org
Fri Jun 25 06:01:25 EDT 2004
Hello Phillip,
On Fri, Jun 25, 2004 at 01:27:03AM -0400, Phillip J. Eby wrote:
> About the only bit you couldn't do in pure Python would be decorating a
> function defined in a nested scope, because "fast locals" aren't accessible
> from pure Python.
Would you believe it? Your implementation works just fine in this case too
:-) sysmodule.c invokes PyFrame_FastToLocals and PyFrame_LocalsToFast around
a call to a trace function, so that any change to f_locals from the trace
function are actually correctly reflected into the frame.
Excellent. Let's put this in the standard library and close the issue ;-)
As an easy extension, decorate(attr=value, ...) could just assign attributes
to the function object. Also, the fact that it works with other assignment
statements is a bonus in my opinion, e.g.:
class X:
decorate(doc("Number of instances created."))
counter = 0
def __init__(self):
X.counter += 1
However, it gets a bit lost if several variables are assigned to in one line.
A bientot,
Armin.
More information about the Python-Dev
mailing list