Skip to content

--warn-redundant-cast doesn’t warn for simple generic types #21796

Description

@flying-sheep

Bug Report
See reproducer

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.12&flags=warn-redundant-casts&gist=f923e1fafbc60a2b7a2fa3c9c3ceb785

from typing import TypeVar, cast

T = TypeVar("T")


def identity(xs: list[T]) -> list[T]:
    return xs


def f(xs: list[int]) -> list[int]:
    reveal_type(identity(xs))
    return cast(list[int], identity(xs))  # --warn-redundant-casts should trigger here

Expected Behavior

warns that the cast is redundant

Actual Behavior

doesn’t warn

Your Environment

  • Mypy version used: 2.3.0
  • Mypy command-line flags: --warn-redundant-casts
  • Mypy configuration options from mypy.ini (and other config files): warn-redundant-casts = true
  • Python version used: any

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions