[Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc. (original) (raw)

Jim Jewett jimjjewett at gmail.com
Tue May 1 16:11:26 CEST 2007


On 4/30/07, Phillip J. Eby <pje at telecommunity.com> wrote:

At 07:29 PM 4/30/2007 -0400, Jim Jewett wrote: >On 4/30/07, Phillip J. Eby <pje at telecommunity.com> wrote:

>>PEP 3115, however, requires that a class' metaclass be determined >>before the class body has executed, making it impossible to use this >>technique for class decoration any more.

>It doesn't say what that metaclass has to do, though.

>Is there any reason the metaclass couldn't delegate differently >depending on the value of mymagicattribute ?

Sure -- that's what I suggested in the "super(), class decorators, and PEP 3115" thread, but Guido voted -1 on adding such a magic attribute to PEP 3115.

I don't think we're understanding each other. Why couldn't you use a suitably fleshed-out version of:

class _ConditionalMetaclass(type):

def __init__(cls, name, bases, dct):
    super(_ConditionalMetaclass, cls).__init__(name, bases, dct)
    hooks = [(k, v) for (k, v) in dct.items() if

k.startswith("afterhook")] for k, v in hooks: cls = AfterHooksRegistry[k](cls, v)

-jJ



More information about the Python-3000 mailing list