X Tutup
The Wayback Machine - https://web.archive.org/web/20250917121502/https://github.com/python/cpython/issues/113904
Skip to content

isinstance support for Union aliases defined by type keyword. (PEP695) #113904

@randolf-scholz

Description

@randolf-scholz

Feature or enhancement

Proposal:

This was pointed out by Nikita Sobolev in #106246 (comment), it seemed worthwhile to have as a separate issue.

from typing import TypeAlias
# old style
Number: TypeAlias = int | float
assert isinstance(0, Number)  # ✅
# new style
type Number = int | float
assert isinstance(0, Number)  # ❌ TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

This prevents changing old code to the new PEP 695 syntax if type aliases define unions and are used in isinstance checks.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    X Tutup