[Python-3000] PEP for Metaclasses in Python 3000 (original) (raw)

Guido van Rossum guido at python.org
Wed Mar 14 19:50:25 CET 2007


On 3/14/07, Jack Diederich <jackdied at jackdied.com> wrote:

I've snipped all the bits I understand and/or agree with.

I'm only quoting what I think needs clarification and/or hasn't already been addressed. Note you're responding to an old thread; Talin posted a new version of the PEP and I checked it in: http://www.python.org/dev/peps/pep-3115/

I don't understand the keyword args other than 'metaclass.' If class D inherits from class C does it also get passed the 'Implements' keyword?

No, it's up to the metaclass to define what happens. It has enough info to tell which interfaces C implements, so if it wants to it can easily make D implement them too without being explicitly told so.

I like the more explicit

class C(metaclass=Implements(I1, I2)): ...

You can do it either way. The PEP however won't force people to do it this way if they like the other way.

Agreed, I currently use metaclasses that pull behavior flags from the class body and it is less than pretty. In my experience when you have those behavior flags in the class they change for every subclass too. If they didn't they would be defined in the original metaclass. I think of metaclasses as 'apply always' and class decorators as 'apply once.'

But that's really between the metaclass and the decorator; the language doesn't constrain you. (I feel I'm repeating myself; we're so deep into meta-land that we can only provide mechanism, not policy on how to use it.)

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



More information about the Python-3000 mailing list