Skip to content

Using isinstance(obj, A | B) incorrectly requires generic parameters for classes #5294

@bryanforbes

Description

@bryanforbes

Describe the bug
Given the following code:

from __future__ import annotations

from typing import Any, Generic, TypeVar

T = TypeVar('T')


class Thing(Generic[T]):
    prop: T


class OtherThing:
    ...


def func(thing: Any) -> None:
    if isinstance(thing, Thing | OtherThing):
        ...

An error is reported at line 17:

Expected type arguments for generic class "Thing"

Expected behavior
No errors are reported

VS Code extension or command-line
Are you running pyright as a VS Code extension, a language server in another editor, or the command-line tool?
Command line

Which version?
1.1.314

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions