From eabf3ddcd1b14ccdc3e2a3375399e7bff4fae955 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 12 Sep 2009 23:48:18 -0700 Subject: [PATCH] Added ugly workaround for a loop bug. --HG-- branch : trunk --- jinja2/compiler.py | 9 +++++++++ tests/test_old_bugs.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 8adb83b..f0deeff 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -647,6 +647,15 @@ class CodeGenerator(NodeVisitor): # macros are delayed, they never require output checks frame.require_output_check = False args = frame.arguments + # XXX: this is an ugly fix for the loop nesting bug + # (tests.test_old_bugs.test_loop_call_bug). This works around + # a identifier nesting problem we have in general. It's just more + # likely to happen in loops which is why we work around it. The + # real solution would be "nonlocal" all the identifiers that are + # leaking into a new python frame and might be used both unassigned + # and assigned. + if 'loop' in frame.identifiers.declared: + args.append('l_loop=l_loop') self.writeline('def macro(%s):' % ', '.join(args), node) self.indent() self.buffer(frame) diff --git a/tests/test_old_bugs.py b/tests/test_old_bugs.py index b004a29..92fb43a 100644 --- a/tests/test_old_bugs.py +++ b/tests/test_old_bugs.py @@ -56,7 +56,7 @@ def test_loop_call_loop(): ''') - assert tmpl.render() == '' + assert tmpl.render().split() == map(unicode, range(1, 11)) * 5 def test_weird_inline_comment(): -- 2.26.2