Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[regression] isinstance complains about parametrized generics with any use of TypeAlias #18488

Copy link
Copy link
Closed
@wesleywright

Description

@wesleywright
Issue body actions

Bug Report

Any attempt to call isinstance with a variable annotated as a TypeAlias seems to result in the error message error: Parameterized generics cannot be used with class or instance checks, even if the aliased type is non-generic. mypy_primer points at #18173 as the breaking commit, but that PR seems to have been intended to deal with type aliases of generic types; it seems that we're treating all TypeAlias-based aliases as generic types, which AFAICT is broader than intended.

To Reproduce

MyPy playground link, using current master

from typing import Any, TypeAlias

class Foo:
    pass

Alias: TypeAlias = Foo

def is_foo(x: Any) -> bool:
    return isinstance(x, Alias)

Expected Behavior

MyPy finds no errors, matching the runtime behavior. Pyright and mypy 1.4 both find no errors in my minimal example.

Actual Behavior

Per the playground link:

main.py:9: error: Parameterized generics cannot be used with class or instance checks  [misc]
Found 1 error in 1 file (checked 1 source file)

Your Environment

I found this when dogfooding mypy master commit c4e2eb7 against Dropbox's internal Python repo, but mypy_primer also reproduces the same thing, as does mypy playground.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongmypy got something wrongtopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctlytopic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.