Skip to content

False positive for "Unnecessary isinstance call" #9272

Open

Description

From version 1.1.380 onwards, Pyright erroneously reports the isinstance below as unnecessary:

class A:
    ...
    
class B(A):
    ...

class C(A):
    ...

def f(elem: B | C, _type: type[A]) -> bool:
    return isinstance(elem, _type)

assert f(B(), B)
assert not f(B(), C)

That would be correct only if type were invariant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't workingregression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions