Skip to content
Myr

Fix custom contexts in fast resolve mode

Before adoption: this commit came in with the history the project adopted, so no landing records it.

closes #675

authored by Adrian Moennich · committed by Adrian Moennich · parent 96f52e6 · Browse files · 3 files+23 added−1 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+23 added−1 removed

  • tests:+14 added−0 removed
  • other:+9 added−1 removed

3 files+23 added−1 removed

modified:jinja2/runtime.py+3 added-1 removed
9 unmodified lines
10"""11import sys1213from itertools import chain14from types import MethodType1516from jinja2.nodes import EvalContext, _context_function_types17from jinja2.utils import Markup, soft_unicode, escape, missing, concat, \18 internalcode, object_type_repr, evalcontextfunction19from jinja2.exceptions import UndefinedError, TemplateRuntimeError, \
148 unmodified lines
168169 # In case we detect the fast resolve mode we can set up an alias170 # here that bypasses the legacy code logic.171 if self._fast_resolve_mode:170 self.resolve_or_missing = resolve_or_missing172 self.resolve_or_missing = MethodType(resolve_or_missing, self)173174 def super(self, name, current):175 """Render a parent block."""176 try:
611 unmodified lines
modified:tests/test_regression.py+14 added
504 unmodified lines
505 assert t.list == [1, 2]506 assert repr(t) == "('foo', [1, 2])"507 assert str(t) == "('foo', [1, 2])"508509 def test_custom_context(self, env):510 from jinja2.runtime import Context511512 class MyContext(Context):513 pass514515 class MyEnvironment(Environment):516 context_class = MyContext517518 loader = DictLoader({'base': '{{ foobar }}',519 'test': '{% extends "base" %}'})520 env = MyEnvironment(loader=loader)521 assert env.get_template('test').render(foobar='test') == 'test'522523 def test_legacy_custom_context(self, env):524 from jinja2.runtime import Context, Undefined, missing525526 class MyContext(Context):
16 unmodified lines
modified:CHANGES+6 added
1Jinja2 Changelog2================34Version 2.9.65-------------6(bugfix release, release date to be decided)78- Fixed custom context behavior in fast resolve mode (#675)910Version 2.9.511-------------12(bugfix release, released on January 28th 2017)13
497 unmodified lines