changeset 579:71e3205925e6

Fix for augmented assignments to local variables. Thanks to Erik Bray for reporting the problem.
author cmlenz
date Tue, 31 Jul 2007 21:40:51 +0000
parents ba660d6032d7
children 4145dd84001e
files ChangeLog genshi/template/eval.py genshi/template/tests/eval.py
diffstat 3 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,13 @@
    speed up rendering of that template a bit.
 
 
+Version 0.4.4
+http://svn.edgewall.org/repos/genshi/tags/0.4.4/
+(?, from branches/stable/0.4.x)
+
+ * Fixed augmented assignment to local variables in Python code blocks.
+
+
 Version 0.4.3
 http://svn.edgewall.org/repos/genshi/tags/0.4.3/
 (Jul 17 2007, from branches/stable/0.4.x)
--- a/genshi/template/eval.py
+++ b/genshi/template/eval.py
@@ -249,7 +249,8 @@
         return {
             '_lookup_name': cls.lookup_name,
             '_lookup_attr': cls.lookup_attr,
-            '_lookup_item': cls.lookup_item
+            '_lookup_item': cls.lookup_item,
+            'UndefinedError': UndefinedError
         }
     globals = classmethod(globals)
 
@@ -653,7 +654,8 @@
         return node
 
     def visitAugAssign(self, node):
-        if isinstance(node.node, ast.Name):
+        if isinstance(node.node, ast.Name) \
+                and node.node.name not in flatten(self.locals[-1]):
             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
@@ -549,6 +549,15 @@
     def test_local_augmented_assign(self):
         Suite("x = 1; x += 42; assert x == 43").execute({})
 
+    def test_augmented_assign_in_def(self):
+        d = {}
+        Suite("""def foo():
+    i = 1
+    i += 1
+    return i
+x = foo()""").execute(d)
+        self.assertEqual(2, 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