Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5036,10 +5036,7 @@ def visit_enum_index_expr(
def visit_cast_expr(self, expr: CastExpr) -> Type:
"""Type check a cast expression."""
source_type = self.accept(
expr.expr,
type_context=AnyType(TypeOfAny.special_form),
allow_none_return=True,
always_allow_any=True,
expr.expr, type_context=None, allow_none_return=True, always_allow_any=True
)
target_type = expr.type
options = self.chk.options
Expand Down
13 changes: 13 additions & 0 deletions test-data/unit/check-warnings.test
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,16 @@ def identity(xs: list[T]) -> list[T]:

def f(xs: list[int]) -> list[int]:
return cast(list[int], identity(xs)) # E: Redundant cast to "list[int]"

[case testRedundantCastGenericCallWithTuple]
# flags: --warn-redundant-casts
from typing import Callable, TypeVar, cast

T = TypeVar("T")

class A: ...

def f(factory: Callable[[], T]) -> tuple[A, T]: ...

cast(tuple[A, A], f(A)) # E: Redundant cast to "tuple[A, A]"
[builtins fixtures/tuple.pyi]
Loading