Thanks to visit codestin.com
Credit goes to github.com

Skip to content

unreachable false positive when using isinstance on class with __call__ when function parameter uses ParamSpec #16024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DetachHead opened this issue Sep 3, 2023 · 2 comments
Labels
bug mypy got something wrong topic-protocols topic-reachability Detecting unreachable code

Comments

@DetachHead
Copy link
Contributor

from typing import Callable, ParamSpec

P = ParamSpec("P")


class Foo:
    def __call__(self) -> None:
        ...


def foo(fn: Callable[P, None]) -> None:
    if isinstance(fn, Foo):
        print("reached") # error: Statement is unreachable  [unreachable]


foo(Foo())

playground

in this example, that line is always reached at runtime

@DetachHead
Copy link
Contributor Author

minified further:

from typing import Callable

def foo(fn: Callable[[], object]) -> None:
    if isinstance(fn, type):
        print(fn)

@sterliakov
Copy link
Collaborator

Works since v1.11.0, resolved in #17389.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-protocols topic-reachability Detecting unreachable code
Projects
None yet
Development

No branches or pull requests

4 participants