Are decorators really that different from metaclasses...
pm_mon at yahoo.com
Tue Aug 31 23:12:41 CEST 2004
Steven Bethard wrote:
> I wrote:
>>What you're suggesting is that given:
>> __author__ = 'Steve'
>> 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'
> 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.
From the interpreter's or system programmer's point of view, you are
absolutely correct. There would be a profoundly different thing going
on under the covers. Specifically, __xxx__ assignments that appear at
the top of function defs would no longer result in local variables.
That is totally different than it is now, you're right.
But I believe that from the application programmer's point of view, not
much will change. That's because of the way (I believe) the majority of
us view __xxx__ assignments (inside of functions) now. When we say
__author__ = 'Morrow'
__version__ = '0.1'
we don't care that __author__ and __version__ become local variables
because foo is most likely not going to use them in its calculation. So
we won't care if later they become something else (attributes of foo).
The semantics of assigning to __author__ or __version__ is the same, in
the eyes of the application programmer, whether the proposed changes are
implemented or not.
More information about the Python-list