PEP 318
Skip Montanaro
skip at pobox.com
Mon Mar 22 14:56:07 EST 2004
>> If easing the creation of class methods is so important, I would prefer
AdSR> Just done a quick check:
AdSR> $ find /lib/python2.3/ -name "*.py" -exec egrep
AdSR> "(class|static)method\W" {} ';' | wc --lines
AdSR> 49
AdSR> Not all of them are calls, and all this in 773 *.py files. I guess
AdSR> this says something about importance...
Not necessarily. Certainly there's the fact that class and static methods
will be less frequently used than normal methods. However, there are also
another mitigating factors as I see it, neither classmethod() nor
staticmethod() have been around all that long (2.2 timeframe).
I will reiterate my comment from before: PEP 318 is about more than just
static and class methods. Here are a few examples from the python-dev
discussion.
1. From Fred Drake:
As an (admittedly trivial) example, I'd be quite happy for:
class Color [valuemap]:
red = rgb(255, 0, 0)
blue = rgb(0, 255, 0)
green = rgb(0, 0, 255)
to cause the name Color to be bound to a non-callable object. Why must
the decorators be required to return callables? It will not make sense
in all circumstances when a decorator is being used.
2. From Anders Munch:
Given that the decorator expression can be an arbitrary Python
expression, it _will_ be used as such. For example:
def foo(arg1, arg2) as release(
version="1.0",
author="me",
status="Well I wrote it so it works, m'kay?",
warning="You might want to use the Foo class instead"):
3. From Shane Hathaway:
Ooh, what about this:
def singleton(klass):
return klass()
class MyThing [singleton]:
...
That would be splendid IMHO.
There are plenty of other examples. Browse the archives.
think-outside-the-bun-(tm)-ly, y'rs,
Skip
More information about the Python-list
mailing list