]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Do not use yield from for blocks with buffers. Fixes #645
authorArmin Ronacher <armin.ronacher@active-4.com>
Sun, 8 Jan 2017 08:27:11 +0000 (09:27 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Sun, 8 Jan 2017 08:27:11 +0000 (09:27 +0100)
CHANGES
jinja2/compiler.py
tests/test_regression.py

diff --git a/CHANGES b/CHANGES
index a31f7d6fe96855c72be51026a97a590002acb662..a860c96a9d085e9584c99e2471af85212ddf75b0 100644 (file)
--- 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
 -------------
index 9051ced6ed40f3b8ba6efd3a15c1d91725dd758c..9a6ac6a034f75df853a2602f1fb9b4278ce277c2 100644 (file)
@@ -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:
index 6f41e89a2bb06b79f355c61fdb37a16fa14b1607..fe16edeef1c2f634d269bc41112d1f16cce73d7b 100644 (file)
@@ -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'