[Python-3000] PEP for Metaclasses in Python 3000

Nick Coghlan ncoghlan at gmail.com
Tue Mar 13 13:47:51 CET 2007


Greg Ewing wrote:
> Nick Coghlan wrote:
>> Along similar lines, I'd be marginally happier with:
>>
>>    class Bob(meta=Planet): pass
> 
> Is there some way we could remove the word "meta"
> from the syntax altogether? I don't mind using
> it in conversation, but it seems a tad too geeky
> to have as an actual part of the language.

If anyone wants to understand metaclass code, they're probably going to 
need to know what the 'm' in 'mcl' stands for...

> How about
> 
>    class Bob(Base1, Base2, class Planet):
>      ...
> 
> i.e. we're saying what we want the class of the
> class to be.

While this is true, calling the class of a class a metaclass provides a 
comforting illusion that the infinite 'class of' recursion terminates 
neatly. (The fact that 'type(type) is type' can be ignored most of the 
time...)

> A benefit would be that the metaclass doesn't
> end up as being one of the keyword args in the
> first place, so there's no issue of whether to
> strip it out or not.

There will already be some special cases here I think - for example, if 
I use the signature:

   def __prepare__(mcl, name, bases, **kwargs):
       #...
   def __new__(mcl, name, bases, attrs, **kwargs):
       #...
   def __init__(cls, name, bases, attrs, **kwargs):
       #...


can a user then do:

   class Bob(meta=Planet, bases=(A, B, C)): pass

and still get a usable class that inherits from A, B & C?

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list