Decorators: an outsider's perspective

Paul Morrow pm_mon at
Mon Aug 16 12:20:18 CEST 2004

Anthony Baxter wrote:
> On Sun, 15 Aug 2004 13:43:30 -0400, Paul Morrow <pm_mon at> wrote:
>>Define fragile.  If you mean, easy to break, I don't see it.  There
>>would be only one way to define an instance method: name its first
>>parameter 'self'.  There would be only one way to define a class method:
>>name its first parameter 'klass' or 'cls' (or some other synoynm that we
>>can all vote on).  All other methods would be static methods.
>>How is that fragile?
> Python currently doesn't _care_ about the argument list, and the variable 
> names in it.

One thought is, to preserve backwards compatability, this special 
behavior would only be invoked for subclasses of the new Object class.

> Adding this sort of behaviour is nasty. How, for instance, would you handle
> adding a method to a class at runtime? Do you poke into the newly added 
> method to make sure you get it right? Do you not do this?

Same rules apply.  The Python system would dynamically determine the 
method's type when you add it (at runtime), so you'd need to make sure 
that the first parm name is correct in advance.

> What about for more complex decorators? Remember, staticmethod and
> classmethod are the trivial cases that this feature addresses. How do you
> handle the more complex ones?

The point is that method type declarations are not needed, so decorators 
wouldn't be concerned with this.  Take them off the list of things 
decorators can do.

More information about the Python-list mailing list