Skip to content

Commit 039ef36

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 e69fb20 commit 039ef36

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
@@ -1097,7 +1097,7 @@ def _paramspec_prepare_subst(self, alias, args):
10971097
params = alias.__parameters__
10981098
i = params.index(self)
10991099
if i == len(args) and self.has_default():
1100-
args = [*args, self.__default__]
1100+
args = (*args, self.__default__)
11011101
if i >= len(args):
11021102
raise TypeError(f"Too few arguments for {alias}")
11031103
# 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)