[pypy-dev] bug with vars() in a nested function
hpk at trillke.net
Tue Dec 23 17:53:20 CET 2003
[Alex Martelli Mon, Dec 22, 2003 at 10:23:24PM +0100]
> The implementation of vars() in builtin.py relies on a call to getdictscope()
> to return the caller's locals as a dir, but unfortunately that doesn't work
> when the caller of built-in vars() is a nested function -- nestedscope.py
> overrides fast2locals to ensure setting in self.w_locals the free variables
> in addition to the locals, and that w_locals is what getdictscope returns.
I think some further CPython analysis would be warranted here.
It's not very easy to see in which code paths and situations
PyFrame_FastToLocals and PyFrame_LocalsToFast in CPython get invoked
regarding nested scopes. In some theoretically critical use cases like exec
and import-star statements the compiler actually forbids it ...
So I committed a fix which modifies fast2locals to not put
bindings from outer scopes into the dict and added some tests (also
the builtin_functions_test now passes). I have the feeling though
that there might be some more dark corners ...
More information about the Pypy-dev