[Python-Dev] PEP 318 restrictions on elements (original) (raw)

[Python-Dev] PEP 318 - generality of list; restrictions on elements

Shane Hathaway shane at zope.com
Mon Mar 8 17:34:18 EST 2004


Fred L. Drake, Jr. wrote:

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)

Ooh, what about this:

 def singleton(klass):
     return klass()

 class MyThing [singleton]:
     ...

That would be splendid IMHO.

However, since MyThing instances aren't necessarily callable, I think my code breaks the rule Aahz is proposing. The 'singleton' decorator has to come last in the decorator list. Also note that the 'singleton' function is not a decorator in the design pattern sense, since the output (an instance) does not implement the same interface as the input (a class).

Shane



More information about the Python-Dev mailing list