Skip to content
Myr

Support block-set in toplevel situations when extends is used

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 0ea221f · Browse files · 3 files+12 added−0 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+12 added−0 removed

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

3 files+12 added−0 removed

modified:jinja2/compiler.py+4 added
1456 unmodified lines
1457 self.export_assigned_vars(frame, assignment_frame)14581459 def visit_AssignBlock(self, node, frame):1460 block_frame = frame.inner()1461 # This is a special case. Since a set block always captures we1462 # will disable output checks. This way one can use set blocks1463 # toplevel even in extended templates.1464 block_frame.require_output_check = False1465 block_frame.inspect(node.body)1466 aliases = self.push_scope(block_frame)1467 self.pull_locals(block_frame)1468 self.buffer(block_frame)
286 unmodified lines
modified:tests/test_regression.py+7 added
282 unmodified lines
283 def test_old_style_attribute(self, env):284 class Foo:285 x = 42286 assert env.getitem(Foo(), 'x') == 42287288 def test_block_set_with_extends(self):289 env = Environment(loader=DictLoader({290 'main': '{% block body %}[{{ x }}]{% endblock %}',291 }))292 t = env.from_string('{% extends "main" %}{% set x %}42{% endset %}')293 assert t.render() == '[42]'
modified:CHANGES+1 added
12 unmodified lines
13- Added support for Python 3.6 async iterators through a new async mode.14- Added policies for filter defaults and similar things.15- urlize now sets "rel noopener" by default.16- Support attribute fallback for old-style classes in 2.x.17- Support toplevel set statements in extend situations.1819Version 2.8.220-------------21
381 unmodified lines