PEP 318

Michele Simionato michele.simionato at
Tue Mar 23 08:52:11 CET 2004

Skip Montanaro <skip at> wrote in message news:<mailman.247.1079985383.742.python-list at>...
> 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.

This one I don't like (not the syntax, the implementation).
I want my singleton to be a class I can derive from.
This can be done by using a metaclass as decorator
(I posted an example months ago).
> There are plenty of other examples.  Browse the archives.
> think-outside-the-bun-(tm)-ly, y'rs,
> Skip
And don't forget Ville Vanio's idea of using the new syntax to
implement multimethods:

def __mul__(self,other) as multimethod(Matrix,Matrix):

def __mul__(self,other) as multimethod(Matrix,Vector):

def __mul__(self,other) as multimethod(Matrix,Scalar):

def __mul__(self,other) as multimethod(Vector,Vector):

def __mul__(self,other) as multimethod(Vector,Scalar):


Way cool, actually :)

   Michele Simionato

More information about the Python-list mailing list