Skip to content

Commit 46ab3ac

Browse files
committed
Use TypeAliasType backport for <3.14
1 parent 94b8c86 commit 46ab3ac

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

src/typing_extensions.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,36 +3528,9 @@ def __ror__(self, other):
35283528
return typing.Union[other, self]
35293529

35303530

3531-
if hasattr(typing, "TypeAliasType") and sys.version_info >= (3, 14):
3531+
if sys.version_info >= (3, 14):
35323532
TypeAliasType = typing.TypeAliasType
3533-
# 3.12-3.13
3534-
elif hasattr(typing, "TypeAliasType"):
3535-
3536-
class TypeAliasType:
3537-
3538-
def __new__(self, name: str, value, *, type_params=()):
3539-
default_value_encountered = False
3540-
for type_param in type_params:
3541-
if not isinstance(type_param,
3542-
(typing.TypeVar, typing.TypeVarTuple, typing.ParamSpec)
3543-
):
3544-
raise TypeError(f"Expected a type param, got {type_param!r}")
3545-
has_default = (
3546-
getattr(type_param, '__default__', NoDefault) is not NoDefault
3547-
)
3548-
if default_value_encountered and not has_default:
3549-
raise TypeError(f'non-default type parameter {type_param!r}'
3550-
' follows default type parameter')
3551-
if has_default:
3552-
default_value_encountered = True
3553-
3554-
return typing.TypeAliasType(name, value, type_params=type_params)
3555-
3556-
def __init_subclass__(cls, *args, **kwargs):
3557-
raise TypeError(
3558-
"type 'typing_extensions.TypeAliasType' is not an acceptable base type"
3559-
)
3560-
3533+
# 3.8-3.13
35613534
else:
35623535
def _is_unionable(obj):
35633536
"""Corresponds to is_unionable() in unionobject.c in CPython."""

0 commit comments

Comments
 (0)