Skip to content
Myr

Use correct concat function for blocks evaluation (#1702)

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

authored by David Lord · committed by GitHub · parents 791dd3b, d3a0b1a · Browse files · 3 files+16 added−2 removed
This commit

State

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

Diff stats

3 files+16 added−2 removed

  • tests:+10 added−0 removed
  • other:+6 added−2 removed

3 files+16 added−2 removed

modified:src/jinja2/runtime.py+4 added-2 removed
365 unmodified lines
366 return BlockReference(self.name, self._context, self._stack, self._depth + 1)367368 @internalcode369 async def _async_call(self) -> str:370 rv = concat(370 rv = self._context.environment.concat( # type: ignore371 [x async for x in self._stack[self._depth](self._context)] # type: ignore372 )373374 if self._context.eval_ctx.autoescape:
5 unmodified lines
380 def __call__(self) -> str:381 if self._context.environment.is_async:382 return self._async_call() # type: ignore383384 rv = concat(self._stack[self._depth](self._context))384 rv = self._context.environment.concat( # type: ignore385 self._stack[self._depth](self._context)386 )387388 if self._context.eval_ctx.autoescape:389 return Markup(rv)390
668 unmodified lines
modified:tests/test_nativetypes.py+10 added
158 unmodified lines
159 t = env.from_string("{%- macro x() -%}{{- [1,2] -}}{%- endmacro -%}{{- x()[1] -}}")160 result = t.render()161 assert result == 2162 assert isinstance(result, int)163164165def test_block(env):166 t = env.from_string(167 "{% block b %}{% for i in range(1) %}{{ loop.index }}{% endfor %}"168 "{% endblock %}{{ self.b() }}"169 )170 result = t.render()171 assert result == 11172 assert isinstance(result, int)
modified:CHANGES.rst+2 added
12 unmodified lines
13- Avoid leaving ``root_render_func()`` unclosed in14 ``Template.generate_async``. :pr:`1960`15- Avoid leaving async generators unclosed in blocks, includes and extends.16 :pr:`1960`17- The runtime uses the correct ``concat`` function for the current environment18 when calling block references. :issue:`1701`192021Version 3.1.422-------------
994 unmodified lines