(
self, node: nodes.Expr
)
| 797 | return node |
| 798 | |
| 799 | def parse_subscript( |
| 800 | self, node: nodes.Expr |
| 801 | ) -> t.Union[nodes.Getattr, nodes.Getitem]: |
| 802 | token = next(self.stream) |
| 803 | arg: nodes.Expr |
| 804 | |
| 805 | if token.type == "dot": |
| 806 | attr_token = self.stream.current |
| 807 | next(self.stream) |
| 808 | if attr_token.type == "name": |
| 809 | return nodes.Getattr( |
| 810 | node, attr_token.value, "load", lineno=token.lineno |
| 811 | ) |
| 812 | elif attr_token.type != "integer": |
| 813 | self.fail("expected name or number", attr_token.lineno) |
| 814 | arg = nodes.Const(attr_token.value, lineno=attr_token.lineno) |
| 815 | return nodes.Getitem(node, arg, "load", lineno=token.lineno) |
| 816 | if token.type == "lbracket": |
| 817 | args: t.List[nodes.Expr] = [] |
| 818 | while self.stream.current.type != "rbracket": |
| 819 | if args: |
| 820 | self.stream.expect("comma") |
| 821 | args.append(self.parse_subscribed()) |
| 822 | self.stream.expect("rbracket") |
| 823 | if len(args) == 1: |
| 824 | arg = args[0] |
| 825 | else: |
| 826 | arg = nodes.Tuple(args, "load", lineno=token.lineno) |
| 827 | return nodes.Getitem(node, arg, "load", lineno=token.lineno) |
| 828 | self.fail("expected subscript expression", token.lineno) |
| 829 | |
| 830 | def parse_subscribed(self) -> nodes.Expr: |
| 831 | lineno = self.stream.current.lineno |
no test coverage detected