[Python-Dev] Re: Plea for function/method syntax sugar (PEP 318, with a different syntax)

Phillip J. Eby pje at telecommunity.com
Thu Feb 19 15:33:07 EST 2004

At 08:45 PM 2/19/04 +0100, Thomas Heller wrote:

>But there is not really a dramatical advantage over this notation, with
>a suitable metaclass:
>class Foo(object):
>     __metaclass__ = SomeMetaclass
>     __provides__ = [IFoo]

Actually, there *is* a dramatic advantage over that notation, since the 
idea is to allow the object to retain its *own* metaclass, not force it to 
use a different one.

The "magic" syntax used by Zope and PyProtocols leaves the original class 
definition's metaclass completely unchanged, and the class decorator syntax 
could do the same.

I'm not really strongly arguing for class decorator syntax, though, because 
the "magic" approach works well enough for me.  I'm just pointing out that 
there *is* a reasonable use case for it.  (Also, the "magic" approach has 
an additional disadvantage, in that if someone explicitly sets 
__metaclass__ *after* a magic function, it will silently prevent the magic 
from occurring.  The class decorator syntax wouldn't have this problem.)

While we're on the subject of PEP 318, I'd also like to mention that I find 

def foo() as bar:

syntax much more readable than the:

def foo() [bar]:

syntax.  But I'll take whatever I can get.  :)

More information about the Python-Dev mailing list