Skip to content

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

Open

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

Activity

  1. Yoruxyv commented on Aug 2, 2026

    @Yoruxyv

    Hi! I’d be happy to take a look at this if no one is already working on it. I’ll first reproduce the issue on current main, then investigate the redundant-cast check and add a focused regression test with the fix. I’ll keep the change scoped to this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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