changeset 582:b21da79c9bde

Follow-up fix to [693:694]. Again, thanks to Erik Bray for reporting.
author cmlenz
date Wed, 01 Aug 2007 16:22:05 +0000
parents 4145dd84001e
children 84137a71a4ca
files genshi/template/eval.py genshi/template/tests/eval.py
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)])
--- 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"}
Copyright (C) 2012-2017 Edgewall Software