https://github.com/python/cpython/commit/d43f47bdcacc028da321945879d10351ac47c1bf
commit: d43f47bdcacc028da321945879d10351ac47c1bf
branch: 3.13
author: Jelle Zijlstra <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-06-24T20:08:56Z
summary:
[3.13] gh-151955: Allow more ParamSpec bounds (#152122)
gh-151955: Allow more ParamSpec and TypeVarTuple bounds (#151956)
(cherry picked from commit 0fb82b46df7bc95c2ba816afba56ff6a6c51caaf)
files:
A Misc/NEWS.d/next/Library/2026-06-22-18-01-00.gh-issue-151955.6u5iwm.rst
M Lib/test/test_typing.py
M Objects/typevarobject.c
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index b3ef0ff4af94f3..5e7f40c42b52e9 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -10046,6 +10046,17 @@ def test_paramspec_in_nested_generics(self):
self.assertEqual(G2[[int, str], float], list[C])
self.assertEqual(G3[[int, str], float], list[C] | int)
+ def test_paramspec_bound(self):
+ P = ParamSpec('P', bound=[int, str])
+ self.assertEqual(P.__bound__, [int, str])
+ P2 = ParamSpec('P2', bound=(int, str))
+ self.assertEqual(P2.__bound__, (int, str))
+ obj = object()
+ P3 = ParamSpec('P3', bound=obj)
+ self.assertIs(P3.__bound__, obj)
+ P4 = ParamSpec('P4')
+ self.assertIs(P4.__bound__, None)
+
def test_paramspec_gets_copied(self):
# bpo-46581
P = ParamSpec('P')
diff --git
a/Misc/NEWS.d/next/Library/2026-06-22-18-01-00.gh-issue-151955.6u5iwm.rst
b/Misc/NEWS.d/next/Library/2026-06-22-18-01-00.gh-issue-151955.6u5iwm.rst
new file mode 100644
index 00000000000000..243b3308a57ad3
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-06-22-18-01-00.gh-issue-151955.6u5iwm.rst
@@ -0,0 +1,2 @@
+Allow more types to be used in the ``bound`` argument to
+:class:`typing.ParamSpec`.
diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c
index cc8de455872604..239911ab528a89 100644
--- a/Objects/typevarobject.c
+++ b/Objects/typevarobject.c
@@ -1061,20 +1061,12 @@ paramspec_new_impl(PyTypeObject *type, PyObject *name,
PyObject *bound,
PyErr_SetString(PyExc_ValueError, "Variance cannot be specified with
infer_variance.");
return NULL;
}
- if (bound != NULL) {
- bound = type_check(bound, "Bound must be a type.");
- if (bound == NULL) {
- return NULL;
- }
- }
PyObject *module = caller();
if (module == NULL) {
- Py_XDECREF(bound);
return NULL;
}
PyObject *ps = (PyObject *)paramspec_alloc(
name, bound, default_value, covariant, contravariant, infer_variance,
module);
- Py_XDECREF(bound);
Py_DECREF(module);
return ps;
}
_______________________________________________
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]