Skip to content

warn redundant casts doesn't work with Protocol.__call__ #12328

Closed
@graingert

Description

@graingert

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions