Rather than decorators, how about sections?
Stefan Eischet
stefan at eischet.com
Wed Aug 11 12:47:20 EDT 2004
Hi,
do we really need this stuff just to say "staticmethod" and
"classmethod"? How about:
class Foo(object):
def baz():
print "Static Method"
def bar(self):
print "Method"
def spam(Foo):
print "Class Method"
Notice that the "normal" method, as usual, contains "self" as a first
argument, while the static method does not. This would probably require
making "self" a keyword; perhaps someone with more knowledge about
Python internals could comment on this? Is anyone using another first
parameter, e.g. "this"?
I'm not sure about the class method syntax, though; better ideas anyone?
I'm not saying you shouldn't have your pie-or-whatever decorators for
other purposes, but I think that the above would be sufficient to solve
the original problem of staticmethod/classmethod just as well.
Someone recently said that, as a new feature, decorators should look
new. I'd say that especially the rusty old feature of static methods
should *not* have a new look.
Cheers,
Stefan
On 11.08.2004, at 17:38, Paul Morrow wrote:
> I like many am not wild about the <at> operator. I also don't think
> that the decorator syntax should be so directly attached to the
> method, since what we're trying to do is to say something about the
> *relationship between* a method and a class (e.g. "method m is a
> staticmethod of class C").
>
> So if we are going to extend the Python grammar to support this sort
> of thing (which I believe is a good idea), my preference would be to
> introduce named sections within a class definition, such as...
>
> class Foo(object):
> staticmethods:
> def baz(a,b):
> print "I'm a static method."
> def bez(c,d):
> print "I'm a static method too."
>
> classmethods:
> def biz(klass):
> print "I'm a class method."
>
>
> def __init__(self):
> print "We all know what I am."
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
// stefan at eischet.com //
More information about the Python-list
mailing list