Metaclass with name overloading.

Alex Martelli aleaxit at
Mon Sep 27 23:02:55 CEST 2004

Bengt Richter <bokr at> wrote:
> If there were a way to make a local bare name access work like a property
> or other descriptor, by designating such names suitably, then def f...
> could trigger the setter of an f property and that could do whatever.
> It might be interesting for a function closure variables also, but here
> we are talking about class bodies. Here is a straw man:

In the current implementation, class bodies are made into functions and
run once.  If you could use anything but a plain dict as the f_locals of
the frame, you could implement your proposed syntax and anything else
you could dream of.  But look at ceval.c and tell me how you'd tell the
functions therein to use a certain special factory for a frame's
f_locals without rewriting hundreds of lines of pretty complicated code.

If the implementation is hard to explain, it's a bad idea.  So let's
find a simple-to-explain implementation; if we can't, it's a bad idea.

> Optimization is for later ;-)

So is syntax.  Let's focus first on how to implement 'smart frames' that
can either use dict (and be fast) or a generic mapping-factory depending
e.g. on a bit in the per-thread state -- for now we can set that bit
with some sys.whatever call, who cares, once the implementation is good
then we can start to wrestle about syntax-sugar issues for it...


More information about the Python-list mailing list