Navigation Menu

Skip to content

Commit

Permalink
Added ugly workaround for a loop bug.
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
mitsuhiko committed Sep 13, 2009
1 parent b4da9be commit eabf3dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions jinja2/compiler.py
Expand Up @@ -647,6 +647,15 @@ def macro_body(self, node, frame, children=None):
# 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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_old_bugs.py
Expand Up @@ -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():
Expand Down

0 comments on commit eabf3dd

Please sign in to comment.