(self, node: nodes.Output, frame: Frame)
| 1477 | self.write(")") |
| 1478 | |
| 1479 | def visit_Output(self, node: nodes.Output, frame: Frame) -> None: |
| 1480 | # If an extends is active, don't render outside a block. |
| 1481 | if frame.require_output_check: |
| 1482 | # A top-level extends is known to exist at compile time. |
| 1483 | if self.has_known_extends: |
| 1484 | return |
| 1485 | |
| 1486 | self.writeline("if parent_template is None:") |
| 1487 | self.indent() |
| 1488 | |
| 1489 | finalize = self._make_finalize() |
| 1490 | body: t.List[t.Union[t.List[t.Any], nodes.Expr]] = [] |
| 1491 | |
| 1492 | # Evaluate constants at compile time if possible. Each item in |
| 1493 | # body will be either a list of static data or a node to be |
| 1494 | # evaluated at runtime. |
| 1495 | for child in node.nodes: |
| 1496 | try: |
| 1497 | if not ( |
| 1498 | # If the finalize function requires runtime context, |
| 1499 | # constants can't be evaluated at compile time. |
| 1500 | finalize.const |
| 1501 | # Unless it's basic template data that won't be |
| 1502 | # finalized anyway. |
| 1503 | or isinstance(child, nodes.TemplateData) |
| 1504 | ): |
| 1505 | raise nodes.Impossible() |
| 1506 | |
| 1507 | const = self._output_child_to_const(child, frame, finalize) |
| 1508 | except (nodes.Impossible, Exception): |
| 1509 | # The node was not constant and needs to be evaluated at |
| 1510 | # runtime. Or another error was raised, which is easier |
| 1511 | # to debug at runtime. |
| 1512 | body.append(child) |
| 1513 | continue |
| 1514 | |
| 1515 | if body and isinstance(body[-1], list): |
| 1516 | body[-1].append(const) |
| 1517 | else: |
| 1518 | body.append([const]) |
| 1519 | |
| 1520 | if frame.buffer is not None: |
| 1521 | if len(body) == 1: |
| 1522 | self.writeline(f"{frame.buffer}.append(") |
| 1523 | else: |
| 1524 | self.writeline(f"{frame.buffer}.extend((") |
| 1525 | |
| 1526 | self.indent() |
| 1527 | |
| 1528 | for item in body: |
| 1529 | if isinstance(item, list): |
| 1530 | # A group of constant data to join and output. |
| 1531 | val = self._output_const_repr(item) |
| 1532 | |
| 1533 | if frame.buffer is None: |
| 1534 | self.writeline("yield " + val) |
| 1535 | else: |
| 1536 | self.writeline(val + ",") |
nothing calls this directly
no test coverage detected