diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 276e183a6bf0..c5e4589ec025 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -144,9 +144,6 @@ def ast3_parse( ) -NamedExpr = ast3.NamedExpr -Constant = ast3.Constant - if sys.version_info >= (3, 10): Match = ast3.Match MatchValue = ast3.MatchValue @@ -957,7 +954,7 @@ def do_func_def( # for ellipsis arg if ( len(func_type_ast.argtypes) == 1 - and isinstance(func_type_ast.argtypes[0], Constant) + and isinstance(func_type_ast.argtypes[0], ast3.Constant) and func_type_ast.argtypes[0].value is Ellipsis ): if n.returns: @@ -1492,7 +1489,7 @@ def visit_Continue(self, n: ast3.Continue) -> ContinueStmt: # --- expr --- - def visit_NamedExpr(self, n: NamedExpr) -> AssignmentExpr: + def visit_NamedExpr(self, n: ast3.NamedExpr) -> AssignmentExpr: s = AssignmentExpr(self.visit(n.target), self.visit(n.value)) return self.set_line(s, n) @@ -1648,8 +1645,8 @@ def visit_Call(self, n: Call) -> CallExpr: ) return self.set_line(e, n) - # Constant(object value) -- a constant, in Python 3.8. - def visit_Constant(self, n: Constant) -> Any: + # Constant(object value) + def visit_Constant(self, n: ast3.Constant) -> Any: val = n.value e: Any = None if val is None: @@ -1773,8 +1770,6 @@ def visit_Tuple(self, n: ast3.Tuple) -> TupleExpr: e = TupleExpr(self.translate_expr_list(n.elts)) return self.set_line(e, n) - # --- slice --- - # Slice(expr? lower, expr? upper, expr? step) def visit_Slice(self, n: ast3.Slice) -> SliceExpr: e = SliceExpr(self.visit(n.lower), self.visit(n.upper), self.visit(n.step)) @@ -2030,9 +2025,9 @@ def translate_argument_list(self, l: Sequence[ast3.expr]) -> TypeList: return TypeList([self.visit(e) for e in l], line=self.line) def _extract_argument_name(self, n: ast3.expr) -> str | None: - if isinstance(n, Constant) and isinstance(n.value, str): + if isinstance(n, ast3.Constant) and isinstance(n.value, str): return n.value.strip() - elif isinstance(n, Constant) and n.value is None: + elif isinstance(n, ast3.Constant) and n.value is None: return None self.fail( message_registry.ARG_NAME_EXPECTED_STRING_LITERAL.format(type(n).__name__), @@ -2058,7 +2053,7 @@ def visit_BinOp(self, n: ast3.BinOp) -> Type: uses_pep604_syntax=True, ) - def visit_Constant(self, n: Constant) -> Type: + def visit_Constant(self, n: ast3.Constant) -> Type: val = n.value if val is None: # None is a type. @@ -2114,16 +2109,10 @@ def numeric_type(self, value: object, n: AST) -> Type: numeric_value, type_name, line=self.line, column=getattr(n, "col_offset", -1) ) - def visit_Index(self, n: ast3.Index) -> Type: - # cast for mypyc's benefit on Python 3.9 - value = self.visit(cast(Any, n).value) - assert isinstance(value, Type) - return value - def visit_Slice(self, n: ast3.Slice) -> Type: return self.invalid_type(n, note="did you mean to use ',' instead of ':' ?") - # Subscript(expr value, expr slice, expr_context ctx) # Python 3.9 and later + # Subscript(expr value, expr slice, expr_context ctx) def visit_Subscript(self, n: ast3.Subscript) -> Type: empty_tuple_index = False if isinstance(n.slice, ast3.Tuple):