From 9f038a13efca2a3395193e72d0a0fca742d4d21e Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Wed, 8 Mar 2023 14:20:10 +0000 Subject: [PATCH] Remove unnecessary casts in `stubtest.py` and `types.py` --- mypy/stubtest.py | 7 ++----- mypy/types.py | 15 ++++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index cd173f63e2a1b..df1c246a82d6f 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -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 @@ -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 # diff --git a/mypy/types.py b/mypy/types.py index 208f1126995c8..2fe532e3d4fcd 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -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" @@ -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" @@ -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" @@ -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" @@ -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)))