]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-138859: Account for `ParamSpec` defaults that are not lists … (GH-138868...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 16 Oct 2025 20:26:29 +0000 (22:26 +0200)
committerGitHub <noreply@github.com>
Thu, 16 Oct 2025 20:26:29 +0000 (13:26 -0700)
gh-138859: Account for `ParamSpec` defaults that are not lists … (GH-138868)
(cherry picked from commit 379fd020a0116754f22b04fa2f7f27a8f7b372b0)

Co-authored-by: bzoracler <50305397+bzoracler@users.noreply.github.com>
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2025-09-13-12-19-17.gh-issue-138859.PxjIoN.rst [new file with mode: 0644]

index f84f972a29437d669d5c0b897cedbc354d6f986b..4b8280b647f647b9dff8e5b4efbbaa71b1f2b69d 100644 (file)
@@ -762,6 +762,16 @@ class TypeParameterDefaultsTests(BaseTestCase):
         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)
index 72c0d7349eaaaa6870525287d6afc372ea9f34f8..92b78defd119763d56c0405ca9f2f1aaa39a8d41 100644 (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.
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 (file)
index 0000000..a5d4dd0
--- /dev/null
@@ -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.