From: Armin Ronacher Date: Sun, 8 Jan 2017 08:27:11 +0000 (+0100) Subject: Do not use yield from for blocks with buffers. Fixes #645 X-Git-Tag: 2.9.3~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f7fa5cdcdd1018f1ca7475145785acc26dd960e;p=thirdparty%2Fjinja.git Do not use yield from for blocks with buffers. Fixes #645 --- diff --git a/CHANGES b/CHANGES index a31f7d6f..a860c96a 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,9 @@ Version 2.9.2 common case that gets copy pasted around. To not completely break backwards compatibility with the most common cases it's now possible to provide an explicit keyword argument for caller if it's given an explicit default. +- Restored the use of blocks in macros to the extend that was possible + before. On Python 3 it would render a generator repr instead of + the block contents. (#645) Version 2.9.1 ------------- diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 9051ced6..9a6ac6a0 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -796,7 +796,8 @@ class CodeGenerator(NodeVisitor): context = node.scoped and ( 'context.derived(%s)' % self.dump_local_context(frame)) or 'context' - if supports_yield_from and not self.environment.is_async: + if supports_yield_from and not self.environment.is_async and \ + frame.buffer is None: self.writeline('yield from context.blocks[%r][0](%s)' % ( node.name, context), node) else: diff --git a/tests/test_regression.py b/tests/test_regression.py index 6f41e89a..fe16edee 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -442,3 +442,8 @@ class TestBug(object): t.module.x(None, caller=lambda: 42) assert exc_info.match(r'\'x\' was invoked with two values for the ' r'special caller argument') + + def test_macro_blocks(self, env): + t = env.from_string('{% macro x() %}{% block foo %}x{% ' + 'endblock %}{% endmacro %}{{ x() }}') + assert t.render() == 'x'