Skip to content
Myr

Add requested patch for safe_repr and nodes.Impossible

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

authored by James Tanner · committed by James Tanner · parent a5d9243 · Browse files · 2 files+19 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

2 files+19 added−1 removed

  • tests:+16 added−0 removed
  • other:+3 added−1 removed

2 files+19 added−1 removed

modified:jinja2/nativetypes.py+3 added-1 removed
1 unmodified line
2from ast import literal_eval3from itertools import islice, chain4from jinja2 import nodes5from jinja2._compat import text_type6from jinja2.compiler import CodeGenerator6from jinja2.compiler import CodeGenerator, has_safe_repr7from jinja2.environment import Environment, Template8from jinja2.utils import concat, escape910
66 unmodified lines
77 if const_finalize is None:78 raise nodes.Impossible()7980 const = child.as_const(frame.eval_ctx)81 if not has_safe_repr(const):82 raise nodes.Impossible()83 except nodes.Impossible:84 body.append(child)85 continue86
134 unmodified lines
modified:tests/test_nativetypes.py+16 added
90 unmodified lines
91 t = env.from_string("{{ '' == None }}")92 result = t.render()93 assert isinstance(result, bool)94 assert result is False9596 def test_variable_dunder(self, env):97 t = env.from_string("{{ x.__class__ }}")98 result = t.render(x=True)99 assert isinstance(result, type)100101 def test_constant_dunder(self, env):102 t = env.from_string("{{ true.__class__ }}")103 result = t.render()104 assert isinstance(result, type)105106 def test_constant_dunder_to_string(self, env):107 t = env.from_string("{{ true.__class__|string }}")108 result = t.render()109 assert not isinstance(result, type)110 assert result == "<type 'bool'>"