[Python-checkins] r66837 - in python/branches/release26-maint: Lib/test/test_set.py Misc/NEWS Objects/setobject.c

amaury.forgeotdarc python-checkins at python.org
Tue Oct 7 22:40:09 CEST 2008


Author: amaury.forgeotdarc
Date: Tue Oct 7 22:40:09 2008
New Revision: 66837
Log:
#4069: aSet.remove(otherSet) would always report the empty frozenset([]) as the missing key.
Now it correctly refers to the initial otherSet.
Backport of r66836.
Modified:
 python/branches/release26-maint/Lib/test/test_set.py
 python/branches/release26-maint/Misc/NEWS
 python/branches/release26-maint/Objects/setobject.c
Modified: python/branches/release26-maint/Lib/test/test_set.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_set.py	(original)
+++ python/branches/release26-maint/Lib/test/test_set.py	Tue Oct 7 22:40:09 2008
@@ -382,6 +382,17 @@
 else:
 self.fail()
 
+ def test_remove_keyerror_set(self):
+ key = self.thetype([3, 4])
+ try:
+ self.s.remove(key)
+ except KeyError as e:
+ self.assert_(e.args[0] is key,
+ "KeyError should be {0}, not {1}".format(key,
+ e.args[0]))
+ else:
+ self.fail()
+
 def test_discard(self):
 self.s.discard('a')
 self.assert_('a' not in self.s)
Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Tue Oct 7 22:40:09 2008
@@ -12,6 +12,11 @@
 Core and Builtins
 -----------------
 
+- Issue #4069: When set.remove(element) is used with a set element, the element
+ is temporarily replaced with an equivalent frozenset. But the eventual
+ KeyError would always report the empty frozenset([]) as the missing key. Now
+ it correctly refers to the initial element.
+
 - Fixed C99 style comments in several files. Python is now C89 compatible
 again.
 
Modified: python/branches/release26-maint/Objects/setobject.c
==============================================================================
--- python/branches/release26-maint/Objects/setobject.c	(original)
+++ python/branches/release26-maint/Objects/setobject.c	Tue Oct 7 22:40:09 2008
@@ -1874,7 +1874,7 @@
 static PyObject *
 set_remove(PySetObject *so, PyObject *key)
 {
-	PyObject *tmpkey, *result;
+	PyObject *tmpkey;
 	int rv;
 
 	rv = set_discard_key(so, key);
@@ -1886,11 +1886,14 @@
 		if (tmpkey == NULL)
 			return NULL;
 		set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key);
-		result = set_remove(so, tmpkey);
+		rv = set_discard_key(so, tmpkey);
 		set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key);
 		Py_DECREF(tmpkey);
-		return result;
-	} else if (rv == DISCARD_NOTFOUND) {
+		if (rv == -1)
+			return NULL;
+	} 
+
+	if (rv == DISCARD_NOTFOUND) {
 		set_key_error(key);
 		return NULL;
 	}


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /