Skip to content

Commit deffc89

Browse files
committed
gh-138859: Account for ParamSpec defaults that are not lists when converting type argument list to tuple
1 parent 805e336 commit deffc89

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
@@ -761,6 +761,16 @@ class A(Generic[T, P, U]): ...
761761
self.assertEqual(A[float, [range]].__args__, (float, (range,), float))
762762
self.assertEqual(A[float, [range], int].__args__, (float, (range,), int))
763763

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

Lib/typing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,8 @@ def _paramspec_prepare_subst(self, alias, args):
11101110
# Convert lists to tuples to help other libraries cache the results.
11111111
elif isinstance(args[i], list):
11121112
args = (*args[:i], tuple(args[i]), *args[i+1:])
1113+
else:
1114+
args = (*args[:i], args[i], *args[i + 1:])
11131115
return args
11141116

11151117

0 commit comments

Comments
 (0)