Bug Report
Here a case where mypy says a cast is redundant, but if you remove the cast, mypy cannot infer the right type.
To Reproduce
Gist
Playground
Expected Behavior
Either no error with the cast or no error without the cast.
Actual Behavior
Using a type cast, mypy says it's not needed.
Without the type cast, mypy cannot infer the type.
Your Environment
- Mypy version used: 2.10
- Mypy configuration options from
mypy.ini (and other config files): warn_redundant_casts = true
- Python version used: 3.14
Bug Report
Here a case where mypy says a cast is redundant, but if you remove the cast, mypy cannot infer the right type.
To Reproduce
Gist
Playground
Expected Behavior
Either no error with the cast or no error without the cast.
Actual Behavior
Using a type cast, mypy says it's not needed.
Without the type cast, mypy cannot infer the type.
Your Environment
mypy.ini(and other config files): warn_redundant_casts = true