[Python-3000] Metaclasses in Py3K

Talin talin at acm.org
Fri Dec 8 19:23:33 CET 2006

Guido van Rossum wrote:
> I've been thinking about this too, and I think it's reasonable to let
> the metaclass provide the dict to be used as locals. This is easier
> when the metaclass is given in the class header, e.g. by way of a base
> class, or through the default metaclass. Although the default default
> metaclass could of course have a hook to pass things on to another
> metaclass specified using a __metaclass__ assignment, I'd rather
> innovate a bit more and add keyword arguments to the class header,
> e.g.
> class C(B1, B2, metaclass=Foo):
>  ...
> How can we design this feature without yet another gigantic
> contentious thread? I'm losing my appetite for those. I wonder if the
> right thing wouldn't be if you could do some serious research into the
> best possible semantics, syntax and implementation, and then post a
> fully-formed proposal (not quite a PEP). There is of course always the
> danger that you might go off into the deep end with that, so I'll
> leave it up to your judgement to decide when to post again. (Also, I'm
> still quite restricted in my internet access, at least until Monday.)

Although, I'm not sure a discussion is needed - I think your syntax is 
fine, better than what we have now, and I have no objection to it.

Here's a use case example:

    # Define a C-struct rectangle
    class Rect(metaclass=ctypes.struct):
       x = ctypes.int32
       y = ctypes.int32
       width = ctypes.int32
       height = ctypes.int32

The only topic for discussion that I see is what the metaclass interface 
should look like. (Please don't start a discussion of flaws in my 
example, it's just an example, don't take it too seriously.)

-- Talin

More information about the Python-3000 mailing list