Skip to content

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

Closed

Description

@DetachHead
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

Activity

  1. DetachHead commented on Sep 5, 2023

    @DetachHead
    ContributorAuthor

    minified further:

    from typing import Callable
    
    def foo(fn: Callable[[], object]) -> None:
        if isinstance(fn, type):
            print(fn)
  2. sterliakov commented on Jan 16, 2025

    @sterliakov
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions