Skip to content

isinstance doesn't work with TypeAlias for classes inherited from NamedTuple #21100

@MAKMED1337

Description

@MAKMED1337

Bug Report

isinstance throws Parameterized generics cannot be used with class or instance checks [misc] for TypeAlias for a class inherited from NamedTuple. This is related to #18488

To Reproduce

from typing import Any, TypeAlias, NamedTuple

class Foo(NamedTuple):
    pass

Alias: TypeAlias = Foo

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

https://mypy-play.net//?mypy=latest&python=3.13&gist=91206dbc88693a2e88ec03e79a8d8235

Expected Behavior
Should not throw.

Actual Behavior
Throws Parameterized generics cannot be used with class or instance checks [misc]

  • Mypy version used: 1.19.1
  • Mypy command-line flags: mypy . --strict
  • Mypy configuration options from pyproject.toml:
[tool.mypy]
strict = true
allow_redefinition = true
allow_redefinition_new = true
local_partial_types = true
follow_untyped_imports = true
  • Python version used: 3.13.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions