Skip to content

Commit 22235b4

Browse files
committed
gh-138859: Account for ParamSpec defaults that are not lists when converting type argument list to tuple
1 parent 3a81313 commit 22235b4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,8 @@ def _paramspec_prepare_subst(self, alias, args):
11231123
# Convert lists to tuples to help other libraries cache the results.
11241124
elif isinstance(args[i], list):
11251125
args = (*args[:i], tuple(args[i]), *args[i+1:])
1126+
else:
1127+
args = (*args[:i], args[i], *args[i + 1:])
11261128
return args
11271129

11281130

0 commit comments

Comments
 (0)