mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Global statements from one function leaked into parallel functions.
Re http://bugs.python.org/issue4315 The symbol table used the same name dictionaries to recursively analyze each of its child blocks, even though the dictionaries are modified during analysis. The fix is to create new temporary dictionaries via the analyze_child_block(). The only information that needs to propagate back up is the names of the free variables. Add more comments and break out a helper function. This code doesn't get any easier to understand when you only look at it once a year.
This commit is contained in:
parent
1e6da5c39f
commit
88f1c04215
2 changed files with 125 additions and 22 deletions
|
|
@ -632,6 +632,30 @@ self.assert_(X.passed)
|
|||
|
||||
f() # used to crash the interpreter...
|
||||
|
||||
def testGlobalInParallelNestedFunctions(self):
|
||||
# A symbol table bug leaked the global statement from one
|
||||
# function to other nested functions in the same block.
|
||||
# This test verifies that a global statement in the first
|
||||
# function does not affect the second function.
|
||||
CODE = """def f():
|
||||
y = 1
|
||||
def g():
|
||||
global y
|
||||
return y
|
||||
def h():
|
||||
return y + 1
|
||||
return g, h
|
||||
|
||||
y = 9
|
||||
g, h = f()
|
||||
result9 = g()
|
||||
result2 = h()
|
||||
"""
|
||||
local_ns = {}
|
||||
global_ns = {}
|
||||
exec CODE in local_ns, global_ns
|
||||
self.assertEqual(2, global_ns["result2"])
|
||||
self.assertEqual(9, global_ns["result9"])
|
||||
|
||||
|
||||
def test_main():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue