https://github.com/python/cpython/commit/379fd020a0116754f22b04fa2f7f27a8f7b372b0
commit: 379fd020a0116754f22b04fa2f7f27a8f7b372b0
branch: main
author: bzoracler <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2025-10-16T05:30:36-07:00
summary:
gh-138859: Account for `ParamSpec` defaults that are not lists … (#138868)
files:
A Misc/NEWS.d/next/Library/2025-09-13-12-19-17.gh-issue-138859.PxjIoN.rst
M Lib/test/test_typing.py
M Lib/typing.py
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index bc7f14f90a7cf9..db0501d70e3442 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -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)
diff --git a/Lib/typing.py b/Lib/typing.py
index 03d5357d4cf51a..25234d2d707dd2 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1113,7 +1113,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.
diff --git
a/Misc/NEWS.d/next/Library/2025-09-13-12-19-17.gh-issue-138859.PxjIoN.rst
b/Misc/NEWS.d/next/Library/2025-09-13-12-19-17.gh-issue-138859.PxjIoN.rst
new file mode 100644
index 00000000000000..a5d4dd042fcd5b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-09-13-12-19-17.gh-issue-138859.PxjIoN.rst
@@ -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.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]