mirror of
https://github.com/python/cpython.git
synced 2025-07-31 07:04:42 +00:00
Fix the 'compiler' package to generate correct code for MAKE_CLOSURE.
In the 2.5 development cycle, MAKE_CLOSURE as changed to take free variables as a tuple rather than as individual items on the stack. Closes patch #1534084.
This commit is contained in:
parent
45381938e9
commit
06ded09d40
3 changed files with 31 additions and 28 deletions
|
@ -104,6 +104,19 @@ class CompilerTest(unittest.TestCase):
|
|||
self.assertEquals(flatten([1, [2]]), [1, 2])
|
||||
self.assertEquals(flatten((1, (2,))), [1, 2])
|
||||
|
||||
def testNestedScope(self):
|
||||
c = compiler.compile('def g():\n'
|
||||
' a = 1\n'
|
||||
' def f(): return a + 2\n'
|
||||
' return f()\n'
|
||||
'result = g()',
|
||||
'<string>',
|
||||
'exec')
|
||||
dct = {}
|
||||
exec c in dct
|
||||
self.assertEquals(dct.get('result'), 3)
|
||||
|
||||
|
||||
NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard)
|
||||
|
||||
###############################################################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue