[Python-3000] super(), class decorators, and PEP 3115

Phillip J. Eby pje at telecommunity.com
Tue May 1 03:13:56 CEST 2007

At 05:38 PM 4/30/2007 -0700, Guido van Rossum wrote:
>Of course, once the core language adds built-in support for such a
>feature, it becomes slightly less advanced, and it is reasonable to
>expect that the special functionality be provided by object or type or
>some other aspect of the standard class definition machinery (maybe
>even a default decorator that's always invoked).

Yep.  That's precisely it.  I'm suggesting that since GF's, enhanced 
super(), and even potentially @abstractmethod have a use for such a hook, 
that this would be an appropriate hook to provide in object or type or 
whatever.  Or, have the MAKE_CLASS opcode just do something like:

       cls = mcls(name, bases, prepared_dict)
       for decorator in cls.__decorators__:
           cls = decorator(cls)

Heck, I'd settle for:

       cls = mcls(name, bases, prepared_dict)
       for callback in cls.__decorators__:

As this version would still handle all of my use cases; it just wouldn't be 
as useful for things like @abstractmethod that really do want to change the 
metaclass or bases rather than simply be notified of what the class is.

More information about the Python-3000 mailing list