Skip to content

Commit d31d526

Browse files
authored
Cleanup fastparse (#20159)
Remove some unused code in mypy/fastparse.py.
1 parent 92101f3 commit d31d526

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

mypy/fastparse.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ def ast3_parse(
144144
)
145145

146146

147-
NamedExpr = ast3.NamedExpr
148-
Constant = ast3.Constant
149-
150147
if sys.version_info >= (3, 10):
151148
Match = ast3.Match
152149
MatchValue = ast3.MatchValue
@@ -957,7 +954,7 @@ def do_func_def(
957954
# for ellipsis arg
958955
if (
959956
len(func_type_ast.argtypes) == 1
960-
and isinstance(func_type_ast.argtypes[0], Constant)
957+
and isinstance(func_type_ast.argtypes[0], ast3.Constant)
961958
and func_type_ast.argtypes[0].value is Ellipsis
962959
):
963960
if n.returns:
@@ -1492,7 +1489,7 @@ def visit_Continue(self, n: ast3.Continue) -> ContinueStmt:
14921489

14931490
# --- expr ---
14941491

1495-
def visit_NamedExpr(self, n: NamedExpr) -> AssignmentExpr:
1492+
def visit_NamedExpr(self, n: ast3.NamedExpr) -> AssignmentExpr:
14961493
s = AssignmentExpr(self.visit(n.target), self.visit(n.value))
14971494
return self.set_line(s, n)
14981495

@@ -1648,8 +1645,8 @@ def visit_Call(self, n: Call) -> CallExpr:
16481645
)
16491646
return self.set_line(e, n)
16501647

1651-
# Constant(object value) -- a constant, in Python 3.8.
1652-
def visit_Constant(self, n: Constant) -> Any:
1648+
# Constant(object value)
1649+
def visit_Constant(self, n: ast3.Constant) -> Any:
16531650
val = n.value
16541651
e: Any = None
16551652
if val is None:
@@ -1773,8 +1770,6 @@ def visit_Tuple(self, n: ast3.Tuple) -> TupleExpr:
17731770
e = TupleExpr(self.translate_expr_list(n.elts))
17741771
return self.set_line(e, n)
17751772

1776-
# --- slice ---
1777-
17781773
# Slice(expr? lower, expr? upper, expr? step)
17791774
def visit_Slice(self, n: ast3.Slice) -> SliceExpr:
17801775
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:
20302025
return TypeList([self.visit(e) for e in l], line=self.line)
20312026

20322027
def _extract_argument_name(self, n: ast3.expr) -> str | None:
2033-
if isinstance(n, Constant) and isinstance(n.value, str):
2028+
if isinstance(n, ast3.Constant) and isinstance(n.value, str):
20342029
return n.value.strip()
2035-
elif isinstance(n, Constant) and n.value is None:
2030+
elif isinstance(n, ast3.Constant) and n.value is None:
20362031
return None
20372032
self.fail(
20382033
message_registry.ARG_NAME_EXPECTED_STRING_LITERAL.format(type(n).__name__),
@@ -2058,7 +2053,7 @@ def visit_BinOp(self, n: ast3.BinOp) -> Type:
20582053
uses_pep604_syntax=True,
20592054
)
20602055

2061-
def visit_Constant(self, n: Constant) -> Type:
2056+
def visit_Constant(self, n: ast3.Constant) -> Type:
20622057
val = n.value
20632058
if val is None:
20642059
# None is a type.
@@ -2114,16 +2109,10 @@ def numeric_type(self, value: object, n: AST) -> Type:
21142109
numeric_value, type_name, line=self.line, column=getattr(n, "col_offset", -1)
21152110
)
21162111

2117-
def visit_Index(self, n: ast3.Index) -> Type:
2118-
# cast for mypyc's benefit on Python 3.9
2119-
value = self.visit(cast(Any, n).value)
2120-
assert isinstance(value, Type)
2121-
return value
2122-
21232112
def visit_Slice(self, n: ast3.Slice) -> Type:
21242113
return self.invalid_type(n, note="did you mean to use ',' instead of ':' ?")
21252114

2126-
# Subscript(expr value, expr slice, expr_context ctx) # Python 3.9 and later
2115+
# Subscript(expr value, expr slice, expr_context ctx)
21272116
def visit_Subscript(self, n: ast3.Subscript) -> Type:
21282117
empty_tuple_index = False
21292118
if isinstance(n.slice, ast3.Tuple):

0 commit comments

Comments
 (0)