Strange interaction between exec, dictionary subtypes, and global variables in 2.4

Alex Martelli aleax at mail.comcast.net
Sat Dec 31 01:39:18 EST 2005


Crutcher <crutcher at gmail.com> wrote:
   ...
> Except that there is some niggling edge case dealing with variables
> which have been marked 'global'. It seems that if a compiled chunk of
> python contains a 'global VAR' statement, anywhere, then that VAR, and
> only that VAR, will bypass the subclassed functions when it is
> accessed.

As we covered on another mailing list today, the presence of that
'global VAR' anywhere means that accesses to that variable get compiled
into bytecodes LOAD_GLOBAL, STORE_GLOBAL, instead of the LOAD_NAME,
STORE_NAME produced when no 'global VAR' is around; and looking at
ceval.c, we see that the use of dictionary subclasses is only supported
for f_locals -- f_globals (and f_builtins) are always used as 'exact'
dict instances instead.  I consider that a bug, even though there might
be a (hopefully miniscule) slowdown in supporting dict subclasses for
f_globals as well as for f_locals.  I know you're now working on a patch
for the issue (and I repeat my recommendation of adding a unit-test for
this issue as part of your patch)... let's see what comes up (the
python-dev mailing list may be more appropriate for this discussion,
btw, since it IS about the development of Python).


Alex



More information about the Python-list mailing list