This commit is contained in:
Yongtao Huang 2025-12-23 16:45:40 +08:00 committed by GitHub
commit a7ef8c5bdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 0 deletions

View file

@ -10029,6 +10029,12 @@ class ParamSpecTests(BaseTestCase):
self.assertEqual(P.__name__, 'P')
self.assertIs(P.__module__, None)
def test_bound(self):
P1 = ParamSpec("P1")
P2 = ParamSpec("P2", bound=None)
self.assertIs(P1.__bound__, None)
self.assertIs(P2.__bound__, None)
def test_valid_uses(self):
P = ParamSpec('P')
T = TypeVar('T')

View file

@ -0,0 +1 @@
Fix ``typing.ParamSpec(..., bound=None)`` so that ``__bound__`` is ``None`` instead of ``NoneType``.

View file

@ -1337,6 +1337,9 @@ paramspec_new_impl(PyTypeObject *type, PyObject *name, PyObject *bound,
PyErr_SetString(PyExc_ValueError, "Variance cannot be specified with infer_variance.");
return NULL;
}
if (Py_IsNone(bound)) {
bound = NULL;
}
if (bound != NULL) {
bound = type_check(bound, "Bound must be a type.");
if (bound == NULL) {