Skip to content

Commit

Permalink
Remove unnecessary casts in stubtest.py and types.py (#14856)
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
AlexWaygood authored Mar 8, 2023
1 parent 2523095 commit dfe0281
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 2 additions & 5 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from contextlib import redirect_stderr, redirect_stdout
from functools import singledispatch
from pathlib import Path
from typing import Any, Generic, Iterator, TypeVar, Union, cast
from typing import Any, Generic, Iterator, TypeVar, Union
from typing_extensions import get_origin

import mypy.build
Expand Down Expand Up @@ -476,10 +476,7 @@ def verify_typeinfo(
to_check = set(stub.names)
# Check all public things on the runtime class
to_check.update(
# cast to workaround mypyc complaints
m
for m in cast(Any, vars)(runtime)
if not is_probably_private(m) and m not in IGNORABLE_CLASS_DUNDERS
m for m in vars(runtime) if not is_probably_private(m) and m not in IGNORABLE_CLASS_DUNDERS
)
# Special-case the __init__ method for Protocols
#
Expand Down
15 changes: 10 additions & 5 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,8 @@ def __init__(

def accept(self, visitor: TypeVisitor[T]) -> T:
assert isinstance(visitor, SyntheticTypeVisitor)
return cast(T, visitor.visit_callable_argument(self))
ret: T = visitor.visit_callable_argument(self)
return ret

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

def accept(self, visitor: TypeVisitor[T]) -> T:
assert isinstance(visitor, SyntheticTypeVisitor)
return cast(T, visitor.visit_type_list(self))
ret: T = visitor.visit_type_list(self)
return ret

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

def accept(self, visitor: TypeVisitor[T]) -> T:
assert isinstance(visitor, SyntheticTypeVisitor)
return cast(T, visitor.visit_raw_expression_type(self))
ret: T = visitor.visit_raw_expression_type(self)
return ret

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

def accept(self, visitor: TypeVisitor[T]) -> T:
assert isinstance(visitor, SyntheticTypeVisitor)
return cast(T, visitor.visit_ellipsis_type(self))
ret: T = visitor.visit_ellipsis_type(self)
return ret

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

def accept(self, visitor: TypeVisitor[T]) -> T:
assert isinstance(visitor, SyntheticTypeVisitor)
return cast(T, visitor.visit_placeholder_type(self))
ret: T = visitor.visit_placeholder_type(self)
return ret

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

0 comments on commit dfe0281

Please sign in to comment.