Are decorators really that different from metaclasses...

Paul Morrow pm_mon at yahoo.com
Sun Aug 29 22:32:21 EDT 2004


Paul Rubin wrote:

> Paul Morrow <pm_mon at yahoo.com> writes:
> 
>>I believe that we should think of assignments to __xxx__ attributes as
>>not being part of the function's body, but instead part of its
>>declaration, just as we do with its docstring.
>>
>>    def circum(diameter):
>>        """This describe's foo."""
>>        __author__ = 'Paul Morrow'
>>        __version__ = '0.1'
> 
> 
> That's fundamentally a pretty good idea, but conflicts with how we
> currently use __xxx__ attributes:
> 
>    def fcn(self, x, y, r):
>       ...
> 
>     class circle(shape):
>        __init__ = fcn
> 
> should work about the same way as
>  
>     class circle(shape):
>        def __init__(self, x, y, r):
>           ...                   # same function as fcn above

I'm not seeing the conflict.  Would you please say a few more words 
about that?

Just so that I'm clear on what I'm saying, I believe that all assignment 
to __xxx__ variables (including assignments to __init__) should be 
executed at object 'defininition time' (i.e. when an object is defined), 
within the context (namespace) of the object being defined.

So in your example [*], the '__init__ = fcn' statement would be executed 
when the interpreter processes the definition of your circle class (when 
it executes the class statement).  When it is finished, circle.__init__ 
would be bound to your fcn function.

Paul

[*] If I'm reading it right --- in my newsreader, the class statement 
appears inside of the def fcn, but I'm assuming that wasn't your intention.




More information about the Python-list mailing list