Title: --warn-redundant-cast doesn’t warn for simple generic types · Issue #21796 · python/mypy · GitHub
Open Graph Title: --warn-redundant-cast doesn’t warn for simple generic types · Issue #21796 · python/mypy
X Title: --warn-redundant-cast doesn’t warn for simple generic types · Issue #21796 · python/mypy
Description: 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]...
Open Graph Description: 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("...
X Description: 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...
Opengraph URL: https://github.com/python/mypy/issues/21796
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"--warn-redundant-cast doesn’t warn for simple generic types","articleBody":"**Bug Report**\nSee reproducer\n\n**To Reproduce**\n\nhttps://mypy-play.net/?mypy=latest&python=3.12&flags=warn-redundant-casts&gist=f923e1fafbc60a2b7a2fa3c9c3ceb785\n\n```python\nfrom typing import TypeVar, cast\n\nT = TypeVar(\"T\")\n\n\ndef identity(xs: list[T]) -> list[T]:\n return xs\n\n\ndef f(xs: list[int]) -> list[int]:\n reveal_type(identity(xs))\n return cast(list[int], identity(xs)) # --warn-redundant-casts should trigger here\n\n```\n\n**Expected Behavior**\n\nwarns that the cast is redundant\n\n**Actual Behavior**\n\ndoesn’t warn\n\n**Your Environment**\n\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\n\n- Mypy version used: 2.3.0\n- Mypy command-line flags: `--warn-redundant-casts`\n- Mypy configuration options from `mypy.ini` (and other config files): `warn-redundant-casts = true`\n- Python version used: any\n\n","author":{"url":"https://github.com/flying-sheep","@type":"Person","name":"flying-sheep"},"datePublished":"2026-07-31T14:40:11Z","url":"https://github.com/python/mypy/issues/21796"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:502a5ff1-d902-3568-0a47-47a334b2b102 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8AFC:3E4AC7:2052ADE:2BB40EC:6B00197F |
| html-safe-nonce | 9e0a7572f8bb063773c400b595306ac9442a89789e78057cbb4ee4ff5fbeb2a8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QUZDOjNFNEFDNzoyMDUyQURFOjJCQjQwRUM6NkIwMDE5N0YiLCJ2aXNpdG9yX2lkIjoiNzE5NTIzNDQ2MzY3NTA2MjY1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 27da65d275a4a13cfe7e158f841d0e2636d4dcb4e2132985c36821bdf5d83fff |
| hovercard-subject-tag | issue:5030605302 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/21796/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1be8a556ff963b74d93a603a4531d72b026682c3455725a0dd9e2a119e3e874c/python/mypy/issues/21796 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1be8a556ff963b74d93a603a4531d72b026682c3455725a0dd9e2a119e3e874c/python/mypy/issues/21796 |
| og:image:alt | 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("... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | flying-sheep |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width