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,
)
| 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 | |
| 608 | class TemplateData(Literal): |
no test coverage detected