[Python-3000] Compiling the PEP 3115 metaclass syntax
Phillip J. Eby
pje at telecommunity.com
Thu Mar 15 17:23:48 CET 2007
At 06:26 PM 3/14/2007 -0700, Guido van Rossum wrote:
>(It's a slightly
>different function than currently; the current function *returns* the
>locals, while the new one *takes* the locals as an argument; instead
>of a LOAD_LOCALS opcode we need a STORE_LOCALS opcode.)
Wouldn't it suffice to exec a code object with the specified locals? Then
the class suite wouldn't even need to be a function, since it would neither
accept parameters nor return results. And no new opcode would be needed.
So in this:
>def __build_class__(func, name, *bases, metaclass=None, **kwds):
> if metaclass is None:
> metaclass = extract_metaclass(bases) # may raise an exception
> prepare = getattr(metaclass, "__prepare__", None)
> if prepare:
> locals = prepare(name, bases, **kwds)
> else:
> locals = {}
> func(locals)
> return metaclass(name, bases, locals, **kwds)
we would change 'func' to 'code' and instead of func(locals) we would 'exec
code in globals, locals'.
More information about the Python-3000
mailing list