There’s a draft of a PEP floating around the Python-3000 list about reforming the way metaclasses are formed. Although I’m not a meta-class programmer by any means, I have read up on them, and appreciate their usefulness in frameworks like Django and SQLObject.
I’ve always thought the syntax wasn’t very pretty __metaclass__ just looking kind of funky.
I guess I’m not alone…from the unfinished PEP:
The other, weaker, rationale is purely cosmetic: The current method
for specifying a metaclass is by assignment to the special variable
__metaclass__, which is considered by some to be aesthetically less
than ideal. Others disagree strongly with that opinion. This PEP
will not address this issue, other than to note it, since aesthetic
debates cannot be resolved via logical proofs.
Specification
In the new model, the syntax for specifying a metaclass is via a
keyword argument in the list of base classes:
class Foo(base1, base2, metaclass=mymeta):
Personally, I like that syntax. It feels less magical, and more like “hey, FYI, the metaclass that’s producing this object is ‘mymeta’.”
I admit to not understanding the usefulness of a bunch of other stuff addressed in the PEP, but that bit I think is good. Metaclasses are a difficult to approach, it feels like you’re hacking something. A gentler syntax makes it seem more reasonable and accepted, less like you’re doing something you shouldn’t.
EDITED TO ADD: the PEP was assigned a number further down the email chain: PEP 3115.

0 Responses to “Metaclass 3000”
Leave a Reply
You must login to post a comment.