| 1613 | self.write(ref) |
| 1614 | |
| 1615 | def visit_NSRef(self, node: nodes.NSRef, frame: Frame) -> None: |
| 1616 | # NSRefs can only be used to store values; since they use the normal |
| 1617 | # `foo.bar` notation they will be parsed as a normal attribute access |
| 1618 | # when used anywhere but in a `set` context |
| 1619 | ref = frame.symbols.ref(node.name) |
| 1620 | self.writeline(f"if not isinstance({ref}, Namespace):") |
| 1621 | self.indent() |
| 1622 | self.writeline( |
| 1623 | "raise TemplateRuntimeError" |
| 1624 | '("cannot assign attribute on non-namespace object")' |
| 1625 | ) |
| 1626 | self.outdent() |
| 1627 | self.writeline(f"{ref}[{node.attr!r}]") |
| 1628 | |
| 1629 | def visit_Const(self, node: nodes.Const, frame: Frame) -> None: |
| 1630 | val = node.as_const(frame.eval_ctx) |