|
18 | 18 |
|
19 | 19 | from astroid import nodes
|
20 | 20 | from astroid._ast import ParserModule, get_parser_module, parse_function_type_comment
|
21 |
| -from astroid.const import IS_PYPY, PY38, PY39_PLUS, Context |
| 21 | +from astroid.const import IS_PYPY, PY38, PY39_PLUS, PY312_PLUS, Context |
22 | 22 | from astroid.manager import AstroidManager
|
23 | 23 | from astroid.nodes import NodeNG
|
24 | 24 | from astroid.nodes.utils import Position
|
@@ -432,6 +432,16 @@ def visit(self, node: ast.TryStar, parent: NodeNG) -> nodes.TryStar:
|
432 | 432 | def visit(self, node: ast.Tuple, parent: NodeNG) -> nodes.Tuple:
|
433 | 433 | ...
|
434 | 434 |
|
| 435 | + if sys.version_info >= (3, 12): |
| 436 | + |
| 437 | + @overload |
| 438 | + def visit(self, node: ast.TypeAlias, parent: NodeNG) -> nodes.TypeAlias: |
| 439 | + ... |
| 440 | + |
| 441 | + @overload |
| 442 | + def visit(self, node: ast.TypeVar, parent: NodeNG) -> nodes.TypeVar: |
| 443 | + ... |
| 444 | + |
435 | 445 | @overload
|
436 | 446 | def visit(self, node: ast.UnaryOp, parent: NodeNG) -> nodes.UnaryOp:
|
437 | 447 | ...
|
@@ -870,6 +880,9 @@ def visit_classdef(
|
870 | 880 | ],
|
871 | 881 | position=self._get_position_info(node, newnode),
|
872 | 882 | doc_node=self.visit(doc_ast_node, newnode),
|
| 883 | + type_params=[self.visit(param, newnode) for param in node.type_params] |
| 884 | + if PY312_PLUS |
| 885 | + else [], |
873 | 886 | )
|
874 | 887 | return newnode
|
875 | 888 |
|
@@ -1170,6 +1183,9 @@ def _visit_functiondef(
|
1170 | 1183 | type_comment_args=type_comment_args,
|
1171 | 1184 | position=self._get_position_info(node, newnode),
|
1172 | 1185 | doc_node=self.visit(doc_ast_node, newnode),
|
| 1186 | + type_params=[self.visit(param, newnode) for param in node.type_params] |
| 1187 | + if PY312_PLUS |
| 1188 | + else [], |
1173 | 1189 | )
|
1174 | 1190 | self._global_names.pop()
|
1175 | 1191 | return newnode
|
@@ -1669,6 +1685,33 @@ def visit_tuple(self, node: ast.Tuple, parent: NodeNG) -> nodes.Tuple:
|
1669 | 1685 | newnode.postinit([self.visit(child, newnode) for child in node.elts])
|
1670 | 1686 | return newnode
|
1671 | 1687 |
|
| 1688 | + def visit_typealias(self, node: ast.TypeAlias, parent: NodeNG) -> nodes.TypeAlias: |
| 1689 | + """Visit a TypeAlias node by returning a fresh instance of it.""" |
| 1690 | + newnode = nodes.TypeAlias( |
| 1691 | + lineno=node.lineno, |
| 1692 | + col_offset=node.col_offset, |
| 1693 | + end_lineno=node.end_lineno, |
| 1694 | + end_col_offset=node.end_col_offset, |
| 1695 | + parent=parent, |
| 1696 | + ) |
| 1697 | + newnode.postinit( |
| 1698 | + type_params=[self.visit(p, newnode) for p in node.type_params], |
| 1699 | + value=self.visit(node.value, newnode), |
| 1700 | + ) |
| 1701 | + return newnode |
| 1702 | + |
| 1703 | + def visit_typevar(self, node: ast.TypeVar, parent: NodeNG) -> nodes.TypeVar: |
| 1704 | + """Visit a TypeVar node by returning a fresh instance of it.""" |
| 1705 | + newnode = nodes.TypeVar( |
| 1706 | + lineno=node.lineno, |
| 1707 | + col_offset=node.col_offset, |
| 1708 | + end_lineno=node.end_lineno, |
| 1709 | + end_col_offset=node.end_col_offset, |
| 1710 | + parent=parent, |
| 1711 | + ) |
| 1712 | + newnode.postinit(name=node.name, bound=self.visit(node.bound, newnode)) |
| 1713 | + return newnode |
| 1714 | + |
1672 | 1715 | def visit_unaryop(self, node: ast.UnaryOp, parent: NodeNG) -> nodes.UnaryOp:
|
1673 | 1716 | """Visit a UnaryOp node by returning a fresh instance of it."""
|
1674 | 1717 | newnode = nodes.UnaryOp(
|
|
0 commit comments