Skip to content
Myr

Fixed a bug in the compiler that caused problems with loop not being referenced in an outer scoped. (Introduced in the last checkin)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent ff53c78 · Browse files · 2 files+11 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−1 removed

  • tests:+9 added−0 removed
  • other:+2 added−1 removed

2 files+11 added−1 removed

modified:jinja2/compiler.py+2 added-1 removed
907 unmodified lines
908 aliases = {}909910 # make sure the loop variable is a special one and raise a template911 # assertion error if a loop tries to write to loop912 if extended_loop:912 loop_frame.identifiers.add_special('loop')913 loop_frame.identifiers.add_special('loop')914 for name in node.find_all(nodes.Name):915 if name.ctx == 'store' and name.name == 'loop':916 self.fail('Can\'t assign to special loop variable '917 'in for-loop target', name.lineno)
505 unmodified lines
modified:tests/test_forloop.py+9 added
142 unmodified lines
143def test_scoped_special_var(env):144 t = env.from_string('{% for s in seq %}[{{ loop.first }}{% for c in s %}'145 '|{{ loop.first }}{% endfor %}]{% endfor %}')146 assert t.render(seq=('ab', 'cd')) == '[True|True|False][False|True|False]'147148149def test_scoped_loop_var(env):150 t = env.from_string('{% for x in seq %}{{ loop.first }}'151 '{% for y in seq %}{% endfor %}{% endfor %}')152 assert t.render(seq='ab') == 'TrueFalse'153 t = env.from_string('{% for x in seq %}{% for y in seq %}'154 '{{ loop.first }}{% endfor %}{% endfor %}')155 assert t.render(seq='ab') == 'TrueFalseTrueFalse'