Skip to content

Commit 1ef3e00

Browse files
committed
Unpack should not pass as a TypeVar
1 parent b38852e commit 1ef3e00

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/test_typing_extensions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7466,11 +7466,11 @@ def test_type_params_possibilities(self):
74667466
((T_default, T), f"non-default type parameter {T!r} follows default"),
74677467
((P_default, P), f"non-default type parameter {P!r} follows default"),
74687468
((Ts_default, T), f"non-default type parameter {T!r} follows default"),
7469-
7470-
# Potentially add invalid inputs, e.g. literals or classes
7471-
# depends on upstream
7469+
# Only type params are accepted
74727470
((1,), "Expected a type param, got 1"),
74737471
((str,), f"Expected a type param, got {str!r}"),
7472+
# Unpack backport behaves like TypeVar in some cases
7473+
((Unpack[Ts],), f"Expected a type param, got {re.escape(repr(Unpack[Ts]))}"),
74747474
]
74757475

74767476
for case in valid_cases:

src/typing_extensions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3611,7 +3611,10 @@ def __init__(self, name: str, value, *, type_params=()):
36113611
default_value_encountered = False
36123612
parameters = []
36133613
for type_param in type_params:
3614-
if not isinstance(type_param, (TypeVar, TypeVarTuple, ParamSpec)):
3614+
if (not isinstance(type_param, (TypeVar, TypeVarTuple, ParamSpec))
3615+
# The Unpack backport passes aboves check
3616+
or _is_unpack(type_param)
3617+
):
36153618
raise TypeError(f"Expected a type param, got {type_param!r}")
36163619
has_default = (
36173620
getattr(type_param, '__default__', NoDefault) is not NoDefault

0 commit comments

Comments
 (0)