MCPcopy
hub / github.com/pallets/jinja / from_untrusted

Method from_untrusted

src/jinja2/nodes.py:591–605  ·  view source on GitHub ↗

Return a const object if the value is representable as constant value in the generated code, otherwise it will raise an `Impossible` exception.

(
        cls,
        value: t.Any,
        lineno: t.Optional[int] = None,
        environment: "t.Optional[Environment]" = None,
    )

Source from the content-addressed store, hash-verified

589
590 @classmethod
591 def from_untrusted(
592 cls,
593 value: t.Any,
594 lineno: t.Optional[int] = None,
595 environment: "t.Optional[Environment]" = None,
596 ) -> "Const":
597 """Return a const object if the value is representable as
598 constant value in the generated code, otherwise it will raise
599 an `Impossible` exception.
600 """
601 from .compiler import has_safe_repr
602
603 if not has_safe_repr(value):
604 raise Impossible()
605 return cls(value, lineno=lineno, environment=environment)
606
607
608class TemplateData(Literal):

Callers 1

generic_visitMethod · 0.80

Calls 2

has_safe_reprFunction · 0.85
ImpossibleClass · 0.85

Tested by

no test coverage detected