Try to optimize a child of an ``Output`` node by trying to convert it to constant, finalized data at compile time. If :exc:`Impossible` is raised, the node is not constant and will be evaluated at runtime. Any other exception will also be evaluated at runtime for eas
(
self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo
)
| 1453 | return repr(concat(group)) |
| 1454 | |
| 1455 | def _output_child_to_const( |
| 1456 | self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo |
| 1457 | ) -> str: |
| 1458 | """Try to optimize a child of an ``Output`` node by trying to |
| 1459 | convert it to constant, finalized data at compile time. |
| 1460 | |
| 1461 | If :exc:`Impossible` is raised, the node is not constant and |
| 1462 | will be evaluated at runtime. Any other exception will also be |
| 1463 | evaluated at runtime for easier debugging. |
| 1464 | """ |
| 1465 | const = node.as_const(frame.eval_ctx) |
| 1466 | |
| 1467 | if frame.eval_ctx.autoescape: |
| 1468 | const = escape(const) |
| 1469 | |
| 1470 | # Template data doesn't go through finalize. |
| 1471 | if isinstance(node, nodes.TemplateData): |
| 1472 | return str(const) |
| 1473 | |
| 1474 | return finalize.const(const) # type: ignore |
| 1475 | |
| 1476 | def _output_child_pre( |
| 1477 | self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo |
no test coverage detected