Skip to content
Myr

Do not use yield from for blocks with buffers. Fixes #645

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 8172db0 · Browse files · 3 files+10 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

3 files+10 added−1 removed

  • tests:+5 added−0 removed
  • other:+5 added−1 removed

3 files+10 added−1 removed

modified:jinja2/compiler.py+2 added-1 removed
794 unmodified lines
795 level += 1796 context = node.scoped and (797 'context.derived(%s)' % self.dump_local_context(frame)) or 'context'798799 if supports_yield_from and not self.environment.is_async:799 if supports_yield_from and not self.environment.is_async and \800 frame.buffer is None:801 self.writeline('yield from context.blocks[%r][0](%s)' % (802 node.name, context), node)803 else:804 loop = self.environment.is_async and 'async for' or 'for'
837 unmodified lines
modified:tests/test_regression.py+5 added
440 unmodified lines
441 with pytest.raises(TypeError) as exc_info:442 t.module.x(None, caller=lambda: 42)443 assert exc_info.match(r'\'x\' was invoked with two values for the '444 r'special caller argument')445446 def test_macro_blocks(self, env):447 t = env.from_string('{% macro x() %}{% block foo %}x{% '448 'endblock %}{% endmacro %}{{ x() }}')449 assert t.render() == 'x'
modified:CHANGES+3 added
11 unmodified lines
12 to macros. While badly buggy and unintended it turns out that this is a13 common case that gets copy pasted around. To not completely break backwards14 compatibility with the most common cases it's now possible to provide an15 explicit keyword argument for caller if it's given an explicit default.16- Restored the use of blocks in macros to the extend that was possible17 before. On Python 3 it would render a generator repr instead of18 the block contents. (#645)1920Version 2.9.121-------------22(bugfix release, released on January 7th 2017)
433 unmodified lines