diff Objects/setobject.c @ 35336:503c3697578f 2.4

Teach set modules to correctly compute s-=s and s^=s as the empty set.
author Raymond Hettinger <python@rcn.com>
date Sat, 13 Aug 2005 02:28:54 +0000
parents dc8ae499efcf
children 97c97194e64b
line wrap: on
line diff
--- a/Objects/setobject.c	Fri Aug 12 23:47:50 2005 +0000
+++ b/Objects/setobject.c	Sat Aug 13 02:28:54 2005 +0000
@@ -193,6 +193,16 @@
 PyDoc_STRVAR(copy_doc, "Return a shallow copy of a set.");
 
 static PyObject *
+set_clear(PySetObject *so)
+{
+	PyDict_Clear(so->data);
+	so->hash = -1;
+	Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(clear_doc, "Remove all elements from this set.");
+
+static PyObject *
 set_union(PySetObject *so, PyObject *other)
 {
 	PySetObject *result;
@@ -379,6 +389,9 @@
 set_difference_update(PySetObject *so, PyObject *other)
 {
 	PyObject *item, *tgtdata, *it;
+
+	if ((PyObject *)so == other)
+		return set_clear(so);
 	
 	it = PyObject_GetIter(other);
 	if (it == NULL)
@@ -758,16 +771,6 @@
 	return 0;
 }
 
-static PyObject *
-set_clear(PySetObject *so)
-{
-	PyDict_Clear(so->data);
-	so->hash = -1;
-	Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(clear_doc, "Remove all elements from this set.");
-
 static int
 set_tp_clear(PySetObject *so)
 {