[Python-3000] Metaclasses in Py3K

Thomas Wouters thomas at python.org
Tue Dec 12 19:11:13 CET 2006

On 12/12/06, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 12/8/06, Guido van Rossum <guido at python.org> 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.

I do wonder about this though: will it require a particular type (like a
dict)? The current code uses fast locals, as a class is essentially a
function (and practically, too; just look at the generated bytecode.) We'd
either need a new mechanism to build classes that was separate from
functions, or we'd have to slow down the entire function execution case to
handler the 'custom locals'. I'm sure people will want it for normal
functions, too, then (debuggers, for instance.) The slowdown might be
reduced to near-insignificant by providing a fast type in C that can proxy
or be subclassed for specific behaviour, but falls back to the same sort of
vector indexing as fast locals. I know, I know, premature optimization and
all, but this is a rather fundamental part of Python's speed.

(Strangely enough, when I tried this out, a with- block that set the
> module-global __metaclass__ seemed to work for classic classes but not
> for new-style classes.  I didn't investigate beyond that.  Code below
> the .sig for those who care.)

That's not strange; only classic classes look at the global __metaclass__ :)
The lookup goes: class dict (setting __metaclass__ in the class suite),
metaclass of parent classes (first one not classic, provided there is no
conflict when inheriting from multiple classes), __metaclass__ module

Thomas Wouters <thomas at python.org>

Hi! I'm a .signature virus! copy me into your .signature file to help me
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20061212/d407b1b8/attachment.html 

More information about the Python-3000 mailing list