Rather than decorators, how about sections?

Christophe Cavalaria chris.cavalaria at free.fr
Wed Aug 11 14:55:25 EDT 2004


Paul Morrow wrote:

>> class Foo(object):
>>     def spam(Foo):
>>         print "Class Method"

What is that ? It's ugly, it's a name alias and it'll be incredibly
confusing when classmethods are inherited, which is exactly the most common
use case for classmethods.

> I like it!  It's simple, clear, ... Why isn't this the hands-down best
> solution? Why do we want to be more verbose than necessary?

It isn't a solution. It only "resolves" the problem for staticmethod and
classmethod which are only a very small part of what we do/want to do with
decorators.

> I wonder if there are people out there who've chosen something other
> than *self* for the 1st arg (shame on them if they did! <grin>) who's
> code this would break.  I've never understood why we didn't require that
> it be called self in the first place --- why give them more than one way
> to do *that*?

Well, it might seem strange but :
- It will break a lot of code which use a name different than self for the
first argument
- It'll break all existing classmethods
- It'll break code that binds arbitrary functions as a member function. You
can't do things like that anymore :

>>> def f(s):
>>>     print "Hi, I'm function f"
>>> class Klass:
>>>     doIt = f
>>> Klass().doIt()




More information about the Python-list mailing list