This commit is contained in:
kljnepk 2026-04-14 07:45:21 +00:00 committed by GitHub
commit f494ce7e4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -1092,7 +1092,11 @@ class CodeGenerator(NodeVisitor):
)
loop_body()
else:
self.writeline("yield from template._get_default_module()._body_stream")
if frame.buffer is None:
self.writeline("yield from template._get_default_module()._body_stream")
else:
self.writeline("for event in template._get_default_module()._body_stream:")
loop_body()
if node.ignore_missing:
self.outdent()

View File

@ -195,6 +195,18 @@ class TestIncludes:
)
assert t.render().strip() == "(FOO)"
def test_include_without_context_inside_macro(self, test_env):
test_env.loader.mapping["included"] = "foo"
t = test_env.from_string(
"""
{%- macro foo() %}
{%- include "included" without context %}
{%- endmacro %}
{{- foo() -}}
"""
)
assert t.render() == "foo"
def test_import_from_with_context(self):
env = Environment(
loader=DictLoader({"a": "{% macro x() %}{{ foobar }}{% endmacro %}"})