diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-15-21-44-08.gh-issue-159486.2yJkXO.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-15-21-44-08.gh-issue-159486.2yJkXO.rst new file mode 100644 index 000000000000000..d493998dbef9dd9 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-15-21-44-08.gh-issue-159486.2yJkXO.rst @@ -0,0 +1 @@ +Speed up ``set >= set``, ``set > set`` and ``set.issuperset()`` on the free-threaded build. diff --git a/Objects/setobject.c b/Objects/setobject.c index 8fdd1eb26118c0a..7b31acf132a7639 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -2418,6 +2418,9 @@ set_issubset_impl(PySetObject *so, PyObject *other) Py_ssize_t pos = 0; int rv; + _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(so); + _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(other); + if (!PyAnySet_Check(other)) { PyObject *tmp = set_intersection(so, other); if (tmp == NULL) { @@ -2460,7 +2463,7 @@ set_issuperset_impl(PySetObject *so, PyObject *other) /*[clinic end generated code: output=ecf00ce552c09461 input=5f2e1f262e6e4ccc]*/ { if (PyAnySet_Check(other)) { - return set_issubset(other, (PyObject *)so); + return set_issubset_impl((PySetObject *)other, (PyObject *)so); } PyObject *key, *it = PyObject_GetIter(other);