Skip to content

Commit 31fd37f

Browse files
bzoraclermiss-islington
authored andcommitted
pythongh-138859: Account for ParamSpec defaults that are not lists … (pythonGH-138868)
(cherry picked from commit 379fd02) Co-authored-by: bzoracler <[email protected]>
1 parent b81bab6 commit 31fd37f

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
@@ -752,6 +752,16 @@ class A(Generic[T, P, U]): ...
752752
self.assertEqual(A[float, [range]].__args__, (float, (range,), float))
753753
self.assertEqual(A[float, [range], int].__args__, (float, (range,), int))
754754

755+
def test_paramspec_and_typevar_specialization_2(self):
756+
T = TypeVar("T")
757+
P = ParamSpec('P', default=...)
758+
U = TypeVar("U", default=float)
759+
self.assertEqual(P.__default__, ...)
760+
class A(Generic[T, P, U]): ...
761+
self.assertEqual(A[float].__args__, (float, ..., float))
762+
self.assertEqual(A[float, [range]].__args__, (float, (range,), float))
763+
self.assertEqual(A[float, [range], int].__args__, (float, (range,), int))
764+
755765
def test_typevartuple_none(self):
756766
U = TypeVarTuple('U')
757767
U_None = TypeVarTuple('U_None', default=None)

Lib/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ def _paramspec_prepare_subst(self, alias, args):
11911191
params = alias.__parameters__
11921192
i = params.index(self)
11931193
if i == len(args) and self.has_default():
1194-
args = [*args, self.__default__]
1194+
args = (*args, self.__default__)
11951195
if i >= len(args):
11961196
raise TypeError(f"Too few arguments for {alias}")
11971197
# 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)