from itertools import islice, chain
from jinja2 import nodes
from jinja2._compat import text_type
-from jinja2.compiler import CodeGenerator
+from jinja2.compiler import CodeGenerator, has_safe_repr
from jinja2.environment import Environment, Template
from jinja2.utils import concat, escape
raise nodes.Impossible()
const = child.as_const(frame.eval_ctx)
+ if not has_safe_repr(const):
+ raise nodes.Impossible()
except nodes.Impossible:
body.append(child)
continue
result = t.render()
assert isinstance(result, bool)
assert result is False
+
+ def test_variable_dunder(self, env):
+ t = env.from_string("{{ x.__class__ }}")
+ result = t.render(x=True)
+ assert isinstance(result, type)
+
+ def test_constant_dunder(self, env):
+ t = env.from_string("{{ true.__class__ }}")
+ result = t.render()
+ assert isinstance(result, type)
+
+ def test_constant_dunder_to_string(self, env):
+ t = env.from_string("{{ true.__class__|string }}")
+ result = t.render()
+ assert not isinstance(result, type)
+ assert result == "<type 'bool'>"