From 6f7fa5cdcdd1018f1ca7475145785acc26dd960e Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 8 Jan 2017 09:27:11 +0100 Subject: [PATCH 1/2] Do not use yield from for blocks with buffers. Fixes #645 --- CHANGES | 3 +++ jinja2/compiler.py | 3 ++- tests/test_regression.py | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index a31f7d6fe..a860c96a9 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 9051ced6e..9a6ac6a03 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -796,7 +796,8 @@ def visit_Block(self, node, frame): 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 6f41e89a2..fe16edeef 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -442,3 +442,8 @@ def test_double_caller_no_default(self, env): 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' From 07c33a5a3c69c771128227213f6e59a11b433121 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 8 Jan 2017 09:27:51 +0100 Subject: [PATCH 2/2] Added bug reference --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index a860c96a9..74d5f7307 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,7 @@ 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. + (#642) - 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)