Are decorators really that different from metaclasses...
Steven Bethard
steven.bethard at gmail.com
Tue Aug 31 15:56:44 EDT 2004
I wrote:
> What you're suggesting is that given:
>
> def f1():
> __author__ = 'Steve'
>
> and
>
> def f2():
> author = 'Steve'
>
> in f1, the assignment to __author__ occurs in the function's namespace, but
> in f2, the assignment to author occurs in the local namespace. Clearly
> then, the __xxx__ format (if at the beginning of a function) changes the
> namespace to which an assignment applies.
Note that the parallel for classes would be if, given:
class F1:
__author__ = 'Steve'
and
class F2:
author = 'Steve'
that the __author__ assignment in F1 occured in one namespace, while the
author assignment in F2 occured in another namespace. (Something like
__author__ only being available from the class object, while author was only
available from class instance objects.) Python could almost certainly be
treat __xxx__ variables to work this way, but it's not the way it works
*now*. This is why I say that you're introducing a totally new semantics to
__xxx__ assignments.
Steve
More information about the Python-list
mailing list