Skip to content
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

Type alias for a union of two @runtime_checkable Protocols triggers "Cannot use parameterized generics in instance checks" #16707

Open
InSyncWithFoo opened this issue Dec 26, 2023 · 0 comments
Labels
bug mypy got something wrong

Comments

@InSyncWithFoo
Copy link
Contributor

Minimal examples

Mypy says I'm using parameterized generics in instance checks, but that's incorrect (playground):

from typing import SupportsIndex, SupportsInt

_ConvertibleToInt = SupportsInt | SupportsIndex

def f(o: object) -> None:
    if isinstance(o, _ConvertibleToInt):  # error
        ...

The same error does not happen if there is no alias (playground):

def f(o: object) -> None:
    if isinstance(o, SupportsInt | SupportsIndex):  # fine
        ...

...or if the alias is for one Protocol and not a union (playground):

_ConvertibleToInt = SupportsInt

def f(o: object) -> None:
    if isinstance(o, _ConvertibleToInt):  # fine
        ...

A union of the same Protocol repeated twice still triggers this error (playground):

_ConvertibleToInt = SupportsInt | SupportsInt

def f(o: object) -> None:
    if isinstance(o, _ConvertibleToInt):  # error
        ...

Environment

  • Versions: 1.7 to 1.8
  • Flags: --strict
  • Python versions: 3.10, 3.11, 3.12
@InSyncWithFoo InSyncWithFoo added the bug mypy got something wrong label Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant