# HG changeset patch # User cmlenz # Date 1185918051 0 # Node ID 2f7f6b70d5b9af05b0e3c6cf80d43be95e05a903 # Parent f0c7ee19a54b02ce9aad0f9533afae906f3cef44 Fix for augmented assignments to local variables. Thanks to Erik Bray for reporting the problem. diff --git a/ChangeLog b/ChangeLog --- 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) diff --git a/genshi/template/eval.py b/genshi/template/eval.py --- 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)]) 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 @@ -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"}