[3.14] gh-138859: Account for ParamSpec defaults that are not lists … (GH-138868) (#140207)

gh-138859: Account for `ParamSpec` defaults that are not lists … (GH-138868)
(cherry picked from commit 379fd020a0)

Co-authored-by: bzoracler <50305397+bzoracler@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-10-16 22:26:29 +02:00 committed by GitHub
parent 12903c098b
commit 54261b6782
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View file

@ -762,6 +762,16 @@ class A(Generic[T, P, U]): ...
self.assertEqual(A[float, [range]].__args__, (float, (range,), float))
self.assertEqual(A[float, [range], int].__args__, (float, (range,), int))
def test_paramspec_and_typevar_specialization_2(self):
T = TypeVar("T")
P = ParamSpec('P', default=...)
U = TypeVar("U", default=float)
self.assertEqual(P.__default__, ...)
class A(Generic[T, P, U]): ...
self.assertEqual(A[float].__args__, (float, ..., float))
self.assertEqual(A[float, [range]].__args__, (float, (range,), float))
self.assertEqual(A[float, [range], int].__args__, (float, (range,), int))
def test_typevartuple_none(self):
U = TypeVarTuple('U')
U_None = TypeVarTuple('U_None', default=None)

View file

@ -1097,7 +1097,7 @@ def _paramspec_prepare_subst(self, alias, args):
params = alias.__parameters__
i = params.index(self)
if i == len(args) and self.has_default():
args = [*args, self.__default__]
args = (*args, self.__default__)
if i >= len(args):
raise TypeError(f"Too few arguments for {alias}")
# Special case where Z[[int, str, bool]] == Z[int, str, bool] in PEP 612.

View file

@ -0,0 +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.