PEP 318 (was Re: [Python-Dev] Re: Guido's Magic Code was: inlinesort option)

Guido van Rossum guido at python.org
Tue Nov 4 10:55:32 EST 2003


> Hmmm -- why is:
> 
> class Foo:
>     __metaclass__ = MetaFoo
>     ...
> 
> "ok", compared to e.g.:
> 
> class Foo is MetaFoo:
>     ...
> 
> while, again for example,
> 
>     def foo():
>         ...
>      foo = staticmethod(foo)
> 
> is presumably deemed "not ok" compared to e.g.:
> 
>     def foo() is staticmethod:
>         ...
> 
> ???
> 
> Both cases of current syntax do the job (perhaps not elegantly but
> they do) and in both cases a new syntax would increase elegance.

Perhaps (I haven't really thought this through) because you can place
the __metaclass__ thing right at the top of the class definition,
while the staticmethod thing must necessarily come after the entire
method definition.  Also I expect that __metaclass__ usage is rather
more rare than static or class methods are.  And often one introduces
a metaclass by inheriting from a base class whose sole (or main)
purpose is to change the metaclass -- just like inheriting from object.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list