Skip to content
Myr

Fixed a scoping bug that caused the immutable scoping rule to be ignored

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

in a few edge cases. This clauses #376. --HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 752ba7f · Browse files · 2 files+16 added−3 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+16 added−3 removed

  • other:+16 added−3 removed

2 files+16 added−3 removed

modified:jinja2/testsuite/regression.py+13 added
160 unmodified lines
161# endif162 ''')163 assert t.render(a=0, b=False, c=42, d=42.0) == '1111C'164165 def test_stacked_locals_scoping_bug_twoframe(self):166 t = Template('''167 {% set x = 1 %}168 {% for item in foo %}169 {% if item == 1 %}170 {% set x = 2 %}171 {% endif %}172 {% endfor %}173 {{ x }}174 ''')175 rv = t.render(foo=[1]).strip()176 assert rv == u'1'177178 def test_call_with_args(self):179 t = Template("""{% macro dump_users(users) -%}180 <ul>181 {%- for user in users -%}
77 unmodified lines
modified:jinja2/compiler.py+3 added-3 removed
291 unmodified lines
292 def visit_If(self, node):293 self.visit(node.test)294 real_identifiers = self.identifiers295296 old_names = real_identifiers.declared | \297 real_identifiers.declared_locally | \296 old_names = real_identifiers.declared_locally | \297 real_identifiers.declared_parameter298299 def inner_visit(nodes):300 if not nodes:
12 unmodified lines
313 else_ = inner_visit(node.else_ or ())314315 # the differences between the two branches are also pulled as316 # undeclared variables318 real_identifiers.undeclared.update(body.symmetric_difference(else_))317 real_identifiers.undeclared.update(body.symmetric_difference(else_) -318 real_identifiers.declared)319320 # remember those that are declared.321 real_identifiers.declared_locally.update(body | else_)322
1311 unmodified lines