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:
Neil Schemenauer 2006-08-04 16:20:30 +00:00
parent 45381938e9
commit 06ded09d40
3 changed files with 31 additions and 28 deletions

View file

@ -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)
###############################################################################