[Python-3000] Metaclasses in Py3K

Josiah Carlson jcarlson at uci.edu
Mon Dec 18 01:44:42 CET 2006

(wasn't quite done with that last message, so I'll just update the parts
where I wasn't finished)

Josiah Carlson <jcarlson at uci.edu> wrote:
> Talin <talin at acm.org> wrote:
> > I don't see why any existing metaclasses would need to be re-written - 
> > see below.

For people using the old syntax, yes, but the old syntax is going away 
(otherwise why offer new syntax?), so rewrites are necessary.

[snip slots stuff]
> The above *still* has the ugliness of needing to state the name of the
> slots attributes as many times as in the original version, which was one
> of the complaints about __slots__ use.  That is to say, the same issue
> that existed with function decorators, exists today with __slots__. 
> There are mechanisms to get around it (using one of the autoslots and
> attribute initializers in the Python cookbook)...
>     class X(object):
>         __metaclass__ = AutoSlots
>         def __init__(self, _x, _y, _z):
>             InitAttrs(self, locals())
> However, I've not been convinced that 

I've not been convinced that removing __metaclass__ and __slots__ is
necessarily a good idea.  Yes, they are ugly.  But they work.  And they
offer a big *HEY SOMETHING IS SPECIAL HERE* marker.

If the point of the syntax change is to remove ugly, fine.  But I think
that the point of changing what exists is to make life easier for people. 
Easier to write, maintain, and understand.

Removing for the sake of removing ugly, your "x = y = z = Slots" works
fine, but it doesn't make understanding it any easier.  It seems like
magic, and the semantics smells quite a bit like the "assignment
decorators" proposal.  But maybe that's just me.

Is __slots__ and __metaclass__ magic?  Sure, but only as much as all
other __meth__ definitions (which aren't going away in Py3k).  The real
trick is that the magic is warned about via the use of double leading
and trailing underscores.  Removing the magic warning isn't helpful,
especially if it is only to remove ugly.

[snip done parts]

 - Josiah

More information about the Python-3000 mailing list