Skip to content

Commit dfe0281

Browse files
authored
Remove unnecessary casts in stubtest.py and types.py (python#14856)
The `stubtest.py` cast is no longer needed -- I think the mypyc issue was fixed by python/typeshed#9146. The `types.py` casts were never needed. They were added relatively recently by somebody called "Alex Waygood".
1 parent 2523095 commit dfe0281

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

mypy/stubtest.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from contextlib import redirect_stderr, redirect_stdout
2626
from functools import singledispatch
2727
from pathlib import Path
28-
from typing import Any, Generic, Iterator, TypeVar, Union, cast
28+
from typing import Any, Generic, Iterator, TypeVar, Union
2929
from typing_extensions import get_origin
3030

3131
import mypy.build
@@ -476,10 +476,7 @@ def verify_typeinfo(
476476
to_check = set(stub.names)
477477
# Check all public things on the runtime class
478478
to_check.update(
479-
# cast to workaround mypyc complaints
480-
m
481-
for m in cast(Any, vars)(runtime)
482-
if not is_probably_private(m) and m not in IGNORABLE_CLASS_DUNDERS
479+
m for m in vars(runtime) if not is_probably_private(m) and m not in IGNORABLE_CLASS_DUNDERS
483480
)
484481
# Special-case the __init__ method for Protocols
485482
#

mypy/types.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,8 @@ def __init__(
950950

951951
def accept(self, visitor: TypeVisitor[T]) -> T:
952952
assert isinstance(visitor, SyntheticTypeVisitor)
953-
return cast(T, visitor.visit_callable_argument(self))
953+
ret: T = visitor.visit_callable_argument(self)
954+
return ret
954955

955956
def serialize(self) -> JsonDict:
956957
assert False, "Synthetic types don't serialize"
@@ -975,7 +976,8 @@ def __init__(self, items: list[Type], line: int = -1, column: int = -1) -> None:
975976

976977
def accept(self, visitor: TypeVisitor[T]) -> T:
977978
assert isinstance(visitor, SyntheticTypeVisitor)
978-
return cast(T, visitor.visit_type_list(self))
979+
ret: T = visitor.visit_type_list(self)
980+
return ret
979981

980982
def serialize(self) -> JsonDict:
981983
assert False, "Synthetic types don't serialize"
@@ -2489,7 +2491,8 @@ def simple_name(self) -> str:
24892491

24902492
def accept(self, visitor: TypeVisitor[T]) -> T:
24912493
assert isinstance(visitor, SyntheticTypeVisitor)
2492-
return cast(T, visitor.visit_raw_expression_type(self))
2494+
ret: T = visitor.visit_raw_expression_type(self)
2495+
return ret
24932496

24942497
def serialize(self) -> JsonDict:
24952498
assert False, "Synthetic types don't serialize"
@@ -2736,7 +2739,8 @@ class EllipsisType(ProperType):
27362739

27372740
def accept(self, visitor: TypeVisitor[T]) -> T:
27382741
assert isinstance(visitor, SyntheticTypeVisitor)
2739-
return cast(T, visitor.visit_ellipsis_type(self))
2742+
ret: T = visitor.visit_ellipsis_type(self)
2743+
return ret
27402744

27412745
def serialize(self) -> JsonDict:
27422746
assert False, "Synthetic types don't serialize"
@@ -2845,7 +2849,8 @@ def __init__(self, fullname: str | None, args: list[Type], line: int) -> None:
28452849

28462850
def accept(self, visitor: TypeVisitor[T]) -> T:
28472851
assert isinstance(visitor, SyntheticTypeVisitor)
2848-
return cast(T, visitor.visit_placeholder_type(self))
2852+
ret: T = visitor.visit_placeholder_type(self)
2853+
return ret
28492854

28502855
def __hash__(self) -> int:
28512856
return hash((self.fullname, tuple(self.args)))

0 commit comments

Comments
 (0)