diff --git a/Objects/setobject.c b/Objects/setobject.c --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1476,6 +1476,10 @@ static int set_difference_update_internal(PySetObject *so, PyObject *other) { + if (PySet_GET_SIZE(so) == 0) { + return 0; + } + if ((PyObject *)so == other) return set_clear_internal(so); @@ -1550,6 +1554,10 @@ Py_ssize_t pos = 0; int rv; + if (PySet_GET_SIZE(so) == 0) { + return set_copy(so); + } + if (!PyAnySet_Check(other) && !PyDict_CheckExact(other)) { return set_copy_and_difference(so, other); }