Amaury Forgeot d'Arc <[EMAIL PROTECTED]> added the comment:

The problem is in PyFrame_LocalsToFast.

(As I understand it: "Locals" refers to the locals() dictionary of the
frame; "Fast" refers to an optimization where local variables are stored
in an array. 
Each call to locals() or the trace function normalizes data by copying
the Fast array into the Locals dictionary; with sys.settrace, the user
may modify the locals, so the inverse transformation is done after each
call to the trace function)

When defining a class, PyFrame_FastToLocals does not copy the free
variables from enclosing scopes. This is the goal of r53954 "Do not copy
free variables to locals in class namespaces".
When executing code in the class body, the sys.settrace function is
called with this reduced set of locals().
The problem is that PyFrame_LocalsToFastdoes does not have the same
test, and uses the locals() to update (and clear) the free variables as
well.

I attach a patch that makes PyFrame_LocalsToFast symmetric to
PyFrame_FastToLocals: in the case of a class statement, do not update 
the free variables.

----------
keywords: +patch
nosy: +jhylton
Added file: http://bugs.python.org/file10707/localstofast.patch

_______________________________________
Python tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue2378>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to