-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Since python 3.10, isinstance
and issubclass
allow testing against Union
-types (PEP604).
However, the same is not true for match-case.
Pitch
case klass():
should probably be 1:1 equivalent with isinstance(x, klass):
.
from typing import TypeAlias
Numeric: TypeAlias = int | float
assert isinstance(1.2, Numeric) # ✔
match 1.2:
case Numeric(): # TypeError: called match pattern must be a type
pass
This carries extra benefits, as TypeAliases
are kind of necessary to write legible code when working with large unions, such as e.g. PythonScalar: TypeAlias = None | bool | int | float | complex | bool | str | datetime | timedelta
.
Linked PRs
Saluev, squeaky-pl, bofm, gjoseph92, mtreglia-gpsw and 2 more
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement