[Python-3000] Metaclasses in Python 3000: Draft 2

Phillip J. Eby pje at telecommunity.com
Thu Mar 15 17:19:35 CET 2007


At 12:13 PM 3/15/2007 +1300, Greg Ewing wrote:
>Phillip J. Eby wrote:
>
> > So the subset required is determined entirely by what the class body
> > (and metaclass __new__) require.
>
>Perhaps the PEP should say something to the effect that
>get, set and delete need to be implemented in order to
>support all the things the class body might want to do,
>but a metaclass can omit them if it wants to restrict
>what can be done in the class body.
>
> > So the metaclass' __new__
> > is going to need to read out the contents of the pseudo-dict somehow, or
> > generate alternative contents.
>
>Maybe the PEP should specify a protocol that the
>pseudo-dict must provide for doing this, such as an
>iteritems() method (or whatever the Py3k equivalent
>is).

That's not necessary; the metaclass instance __call__ (or class __new__) 
should be responsible for passing a real dictionary to type.__new__, if it 
in fact wants to create a type object all.  Remember, metaclasses need not 
be types, nor to create types.  For that matter, it isn't necessarily the 
case that the metaclass will directly map the dictionary "contents" into a 
dictionary at all.  There may be renaming of keys, creation of new keys, 
code generation, and who-knows-what-else.  So, having a protocol for 
transforming the suite locals into a type dictionary would be unnecessarily 
restrictive.



More information about the Python-3000 mailing list