[Python-3000] metaclass syntax [was: Discussions with no PEPs]

Guido van Rossum guido at python.org
Fri Mar 9 17:30:00 CET 2007


On 3/9/07, Phillip J. Eby <pje at telecommunity.com> wrote:
> At 07:06 AM 3/9/2007 -0800, Guido van Rossum wrote:
> >Those look like use cases for metaclasses, but I don't see how they
> >require setting a custom dict *while the class suite is being
> >executed*.
>
> The main use case for that is to know what order the items were defined in;
> currently there's no way to achieve that without say, abusing the debugger
> hook.

I agree, and I have a proposed solution (which Talin knows and will
turn into a PEP). I was just noting that Jim, in a response to Talin's
claim that the only use case for a custom dict was to know the
declaration order, was replying with use cases for metaclasses that
could be solved without a custom dict, hence he wasn't refuting
Talin's claim (as he seemed to think he was).

> There are other interesting use cases that could be achieved with a custom
> dictionary, too, now that I'm thinking about it, that currently require at
> least some level of bytecode hacking or string manipulation.  For example,
> there's a Python Cookbook recipe that does propositional logic and works by
> exec'ing code with a custom dictionary after figuring out what names are
> being used by a function body.  With a custom dictionary for the class
> body, that could be done without exec or bytecode inspection.
>
> I personally can see the possibility of using the feature for implementing
> database schema definition forward references (where you need to be able to
> refer to objects that don't yet exist) in a class body.

Don't worry. This will be possible.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list