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
Feature or enhancement
Since python 3.10,
isinstanceandissubclassallow testing againstUnion-types (PEP604).However, the same is not true for match-case.
Pitch
case klass():should probably be 1:1 equivalent withisinstance(x, klass):.This carries extra benefits, as
TypeAliasesare 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