[Python-Dev] PEP 318 - posting draft

Guido van Rossum guido at python.org
Wed Mar 24 10:40:07 EST 2004


> > But while you're at it, please add to the PEP that I don't like the
> > idea of class decorators.  I think they don't solve a real problem,
> > unlike function decorators, and I think that making classes and
> > functions more similar just adds confusion.
> 
> I disagree.  There's definitely a use case for something less permanent 
> than a metaclass that gets a reference to a class immediately after 
> creation but before it ends up in the module namespace.  For example, 
> ZopeX3 interfaces and PyProtocols interfaces both use sys._getframe() 
> introspection to add a temporary metaclass so that they can declare 
> that a class supports (or does not support) a particular set of 
> interfaces from the class body itself.  Using the [] syntax to decorate 
> the class would deprecate these sorts of nasty hacks.

But the use cases are certainly very *different* than those for
function/method decorators, and should be spelled out separately.

For example, I'd like to see you show in much more detail how class
decorators could be used to replace those Zope3 hacks.

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



More information about the Python-Dev mailing list