To Reproduce
https://mypy-play.net/?mypy=latest&python=3.10&flags=strict%2Cwarn-redundant-casts&gist=bc9999020b0fb32610c0c3ec99a8568c
from typing import Protocol, cast class FooType(Protocol): def __call__(self, ham: str) -> str: pass def foo(ham: str) -> str: pass v = cast(FooType, foo) u: FooType = foo
Expected Behavior I was expecting v = cast(FooType, foo) to work about the same as v: FooType = foo # type: ignore[assignment] with warn redundant ignores
Your Environment
See mypy-play
It seems even very simple redundant casts are not detected:
from typing import cast class Foo: pass class Bar(Foo): pass v = cast(Foo, Bar())
https://mypy-play.net/?mypy=latest&python=3.10&flags=strict%2Cwarn-redundant-casts&gist=c166276e9623ced551d45e7a74d31510
Is the behavior with respect to subtyping documented?
The docs refer to casts that can be safely removed:
https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-warn-redundant-casts
This flag will make mypy report an error whenever your code uses an unnecessary cast that can safely be removed.
Activity
graingert commented on Mar 10, 2022
It seems even very simple redundant casts are not detected:
https://mypy-play.net/?mypy=latest&python=3.10&flags=strict%2Cwarn-redundant-casts&gist=c166276e9623ced551d45e7a74d31510
jhance commented on Mar 11, 2022
Is the behavior with respect to subtyping documented?
graingert commented on Mar 11, 2022
The docs refer to casts that can be safely removed:
https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-warn-redundant-casts