From 0760a572f7f3d17411d4eb828e1483c0008805fb Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Thu, 16 Oct 2025 22:26:24 +0200 Subject: [PATCH] =?utf8?q?[3.13]=20gh-138859:=20Account=20for=20`ParamSpec?= =?utf8?q?`=20defaults=20that=20are=20not=20lists=20=E2=80=A6=20(GH-138868?= =?utf8?q?)=20(#140208)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 10 ++++++++++ Lib/typing.py | 2 +- .../2025-09-13-12-19-17.gh-issue-138859.PxjIoN.rst | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2025-09-13-12-19-17.gh-issue-138859.PxjIoN.rst diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index fb4cf26982d3..abe78c38439e 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -752,6 +752,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) diff --git a/Lib/typing.py b/Lib/typing.py index 95e469c4fff7..35ffaabc719b 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1191,7 +1191,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 000000000000..a5d4dd042fcd --- /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. -- 2.47.3