Skip to content

False negative when matching a Protocol #2581

@lihu-zhong

Description

@lihu-zhong

Summary

Observed behavior:

ty correctly raises an invalid-argument-type error when using a Protocol in an isinstance() check, but doesn't raise the same error when an equivalent runtime check is done with match:

from dataclasses import dataclass
from typing import Any, Protocol


class Foo(Protocol):
    foo: str


@dataclass
class ImplFoo:
    foo: str = "bar"


def isinstance_check(input: Any) -> None:
    if isinstance(input, Foo):
        input.foo


def match_check(input: Any) -> None:
    match input:
        case Foo():
            input.foo


isinstance_check(ImplFoo())
match_check(ImplFoo())

In the above code, ty raises one error.

Expected Behavior:

ty should raise the same error on the match structure, since it raises the same runtime error. mypy misses this as well, but pyright catches it.

Version

0.0.10

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions