# HG changeset patch # User cmlenz # Date 1185985325 0 # Node ID b21da79c9bde803346119030169ce60947b555a7 # Parent 4145dd84001e1674a425b5c210abb3082123d426 Follow-up fix to [693:694]. Again, thanks to Erik Bray for reporting. diff --git a/genshi/template/eval.py b/genshi/template/eval.py --- a/genshi/template/eval.py +++ b/genshi/template/eval.py @@ -655,7 +655,7 @@ def visitAugAssign(self, node): if isinstance(node.node, ast.Name) \ - and node.node.name not in flatten(self.locals[-1]): + and node.node.name not in flatten(self.locals): name = node.node.name node.node = ast.Subscript(ast.Name('data'), 'OP_APPLY', [ast.Const(name)]) diff --git a/genshi/template/tests/eval.py b/genshi/template/tests/eval.py --- a/genshi/template/tests/eval.py +++ b/genshi/template/tests/eval.py @@ -558,6 +558,16 @@ x = foo()""").execute(d) self.assertEqual(2, d['x']) + def test_augmented_assign_in_loop_in_def(self): + d = {} + Suite("""def foo(): + i = 0 + for n in range(5): + i += n + return i +x = foo()""").execute(d) + self.assertEqual(10, d['x']) + def test_assign_in_list(self): suite = Suite("[d['k']] = 'foo',; assert d['k'] == 'foo'") d = {"k": "bar"}