Skip to content

Commit 379fd02

Browse files
authored
pythongh-138859: Account for ParamSpec defaults that are not lists … (python#138868)
1 parent 5a31024 commit 379fd02

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Lib/test/test_typing.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,16 @@ class A(Generic[T, P, U]): ...
762762
self.assertEqual(A[float, [range]].__args__, (float, (range,), float))
763763
self.assertEqual(A[float, [range], int].__args__, (float, (range,), int))
764764

765+
def test_paramspec_and_typevar_specialization_2(self):
766+
T = TypeVar("T")
767+
P = ParamSpec('P', default=...)
768+
U = TypeVar("U", default=float)
769+
self.assertEqual(P.__default__, ...)
770+
class A(Generic[T, P, U]): ...
771+
self.assertEqual(A[float].__args__, (float, ..., float))
772+
self.assertEqual(A[float, [range]].__args__, (float, (range,), float))
773+
self.assertEqual(A[float, [range], int].__args__, (float, (range,), int))
774+
765775
def test_typevartuple_none(self):
766776
U = TypeVarTuple('U')
767777
U_None = TypeVarTuple('U_None', default=None)

Lib/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ def _paramspec_prepare_subst(self, alias, args):
11131113
params = alias.__parameters__
11141114
i = params.index(self)
11151115
if i == len(args) and self.has_default():
1116-
args = [*args, self.__default__]
1116+
args = (*args, self.__default__)
11171117
if i >= len(args):
11181118
raise TypeError(f"Too few arguments for {alias}")
11191119
# Special case where Z[[int, str, bool]] == Z[int, str, bool] in PEP 612.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix generic type parameterization raising a :exc:`TypeError` when omitting a :class:`ParamSpec` that has a default which is not a list of types.

0 commit comments

Comments
 (0)