22# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
33# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
44
5+ from __future__ import annotations
6+
57import ast
68import sys
79import types
810from functools import partial
9- from typing import Dict , List , NamedTuple , Optional , Type
11+ from typing import NamedTuple
1012
1113from astroid .const import PY38_PLUS , Context
1214
1315if sys .version_info >= (3 , 8 ):
1416 # On Python 3.8, typed_ast was merged back into `ast`
15- _ast_py3 : Optional [ types .ModuleType ] = ast
17+ _ast_py3 : types .ModuleType | None = ast
1618else :
1719 try :
1820 import typed_ast .ast3 as _ast_py3
2123
2224
2325class FunctionType (NamedTuple ):
24- argtypes : List [ast .expr ]
26+ argtypes : list [ast .expr ]
2527 returns : ast .expr
2628
2729
2830class ParserModule (NamedTuple ):
2931 module : types .ModuleType
30- unary_op_classes : Dict [ Type [ast .unaryop ], str ]
31- cmp_op_classes : Dict [ Type [ast .cmpop ], str ]
32- bool_op_classes : Dict [ Type [ast .boolop ], str ]
33- bin_op_classes : Dict [ Type [ast .operator ], str ]
34- context_classes : Dict [ Type [ast .expr_context ], Context ]
32+ unary_op_classes : dict [ type [ast .unaryop ], str ]
33+ cmp_op_classes : dict [ type [ast .cmpop ], str ]
34+ bool_op_classes : dict [ type [ast .boolop ], str ]
35+ bin_op_classes : dict [ type [ast .operator ], str ]
36+ context_classes : dict [ type [ast .expr_context ], Context ]
3537
3638 def parse (self , string : str , type_comments : bool = True ) -> ast .Module :
3739 if self .module is _ast_py3 :
@@ -46,7 +48,7 @@ def parse(self, string: str, type_comments: bool = True) -> ast.Module:
4648 return parse_func (string )
4749
4850
49- def parse_function_type_comment (type_comment : str ) -> Optional [ FunctionType ] :
51+ def parse_function_type_comment (type_comment : str ) -> FunctionType | None :
5052 """Given a correct type comment, obtain a FunctionType object"""
5153 if _ast_py3 is None :
5254 return None
@@ -78,13 +80,13 @@ def get_parser_module(type_comments: bool = True) -> ParserModule:
7880
7981def _unary_operators_from_module (
8082 module : types .ModuleType ,
81- ) -> Dict [ Type [ast .unaryop ], str ]:
83+ ) -> dict [ type [ast .unaryop ], str ]:
8284 return {module .UAdd : "+" , module .USub : "-" , module .Not : "not" , module .Invert : "~" }
8385
8486
8587def _binary_operators_from_module (
8688 module : types .ModuleType ,
87- ) -> Dict [ Type [ast .operator ], str ]:
89+ ) -> dict [ type [ast .operator ], str ]:
8890 binary_operators = {
8991 module .Add : "+" ,
9092 module .BitAnd : "&" ,
@@ -105,13 +107,13 @@ def _binary_operators_from_module(
105107
106108def _bool_operators_from_module (
107109 module : types .ModuleType ,
108- ) -> Dict [ Type [ast .boolop ], str ]:
110+ ) -> dict [ type [ast .boolop ], str ]:
109111 return {module .And : "and" , module .Or : "or" }
110112
111113
112114def _compare_operators_from_module (
113115 module : types .ModuleType ,
114- ) -> Dict [ Type [ast .cmpop ], str ]:
116+ ) -> dict [ type [ast .cmpop ], str ]:
115117 return {
116118 module .Eq : "==" ,
117119 module .Gt : ">" ,
@@ -128,7 +130,7 @@ def _compare_operators_from_module(
128130
129131def _contexts_from_module (
130132 module : types .ModuleType ,
131- ) -> Dict [ Type [ast .expr_context ], Context ]:
133+ ) -> dict [ type [ast .expr_context ], Context ]:
132134 return {
133135 module .Load : Context .Load ,
134136 module .Store : Context .Store ,
0 commit comments