Skip to content

[match-case] mypy ignores missing @runtime_checkable in class-pattern #19469

@randolf-scholz

Description

@randolf-scholz
from typing import Any, Callable, Protocol, runtime_checkable

class Proto(Protocol):
    def foo(self, x: int, /) -> object: ...

def test_object(x: object) -> None:
    match x:
        case Proto() as y:  # No Error
            reveal_type(y)  # N: Revealed type is "__main__.Proto"

    if isinstance(x, Proto):  # E: Only @runtime_checkable protocols ...
        reveal_type(x)  # N: Revealed type is "__main__.Proto"

https://mypy-play.net/?mypy=latest&python=3.12&gist=6e3f280e71d3cb4d6131e51496370f97

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-match-statementPython 3.10's match statementtopic-runtime-semanticsmypy doesn't model runtime semantics correctly

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions