[Python-3000] PEP for Metaclasses in Python 3000

Talin talin at acm.org
Sat Mar 10 10:21:46 CET 2007


Greg Ewing wrote:
> Talin wrote:
> 
>>        class Foo(base1, base2, metaclass=mymeta):
>>          ...
> 
> -1 on this syntax, I think it's ugly.

All I can say is, beauty is in the eye, etc...in any case, I'm not the 
one to decide what's pretty and what's not.

> Alternative proposals:
> 
>    class Foo(base1, base2) as MyMeta:
>      ...
> 
> or
> 
>    class Foo(base1, base2) = MyMeta:
>      ...

Neither of these work for me, in the sense that when I read them, they 
don't elicit concepts that match the metaclass concept. The relation 
between a class and a metaclass isn't well-expressed with 'as', 'is', or 
'equals'.

>>        class Foo(base1, base2, metaclass=mymeta, private=True):
>>          ...
> 
>    class Foo(base1, base2) as MyMeta(private=True):
>      ...
> 
> or
> 
>    class Foo(base1, base2) = MyMeta(private=True):
>      ...
> 
>>      This attribute is a method named __metacreate__
> 
> Very bad choice of name -- it's not creating a meta-anything,
> and gives no clue what it is creating.

I didn't want to call it __metadict__, as it was in the earlier 
proposal, because in the current version it's doing more than just 
creating the class dict, it's also processing any additional keywords 
that are passed in to the class base list.

>>      It would be possible to leave the existing __metaclass__ syntax in
>>      place. Alternatively, it would not be too difficult to modify the
>>      syntax rules of the Py3K translation tool to convert from the old to
>>      the new syntax.
> 
> The existing syntax actually has some advantages, e.g.
> you can do things like
> 
>    class Foo:
>      class __metaclass__:
>        # Real class methods defined here
> 
> which I think is rather elegant, so I'm not sure I'd
> like the new syntax to completely replace the old one.

I have no opinion on this - I've never had a need to declare a metaclass 
inline like that.

> --
> Greg
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/talin%40acm.org
> 


More information about the Python-3000 mailing list