`{% call %}` tag inside loops.
This fixes #323.
--HG--
branch : trunk
- Priority of `not` raised. It's now possible to write `not foo in bar`
as an alias to `foo not in bar` like in python. Previously the grammar
required parentheses (`not (foo in bar)`) which was odd.
+- Fixed a bug that caused syntax errors when defining macros or using the
+ `{% call %}` tag inside loops.
Version 2.1.1
-------------
if name not in aliases:
to_delete.add('l_' + name)
if to_delete:
- self.writeline('del ' + ', '.join(to_delete))
+ # we cannot use the del statement here because enclosed
+ # scopes can trigger a SyntaxError:
+ # a = 42; b = lambda: a; del a
+ self.writeline(' = '.join(to_delete) + ' = missing')
def function_scoping(self, node, frame, children=None,
find_special=True):
:license: BSD.
"""
import sys
-from jinja2.utils import CodeType
+from jinja2.utils import CodeType, missing
def translate_exception(exc_info):
else:
locals = {}
for name, value in real_locals.iteritems():
- if name.startswith('l_'):
+ if name.startswith('l_') and value is not missing:
locals[name[2:]] = value
# if there is a local called __jinja_exception__, we get
{%- for item in foo recursive -%}{%- endfor -%}
''')
assert t.render(dict(foo=[])) == ''
+
+
+def test_call_in_loop(env):
+ t = env.from_string('''
+ {%- macro do_something() -%}
+ [{{ caller() }}]
+ {%- endmacro %}
+
+ {%- for i in [1, 2, 3] %}
+ {%- call do_something() -%}
+ {{ i }}
+ {%- endcall %}
+ {%- endfor -%}
+ ''')
+ assert t.render() == '[1][2][3]'