[Python-checkins] r84305 - in python/branches/release27-maint: Lib/_abcoll.py Lib/test/test_collections.py Misc/NEWS

daniel.stutzbach python-checkins at python.org
Tue Aug 24 23:09:30 CEST 2010


Author: daniel.stutzbach
Date: Tue Aug 24 23:09:30 2010
New Revision: 84305

Log:
Merged revisions 84301 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r84301 | daniel.stutzbach | 2010-08-24 15:49:57 -0500 (Tue, 24 Aug 2010) | 1 line
  
  Issue 8750: Fixed MutableSet's methods to correctly handle reflexive operations, namely x -= x and x ^= x
........


Modified:
   python/branches/release27-maint/   (props changed)
   python/branches/release27-maint/Lib/_abcoll.py
   python/branches/release27-maint/Lib/test/test_collections.py
   python/branches/release27-maint/Misc/NEWS

Modified: python/branches/release27-maint/Lib/_abcoll.py
==============================================================================
--- python/branches/release27-maint/Lib/_abcoll.py	(original)
+++ python/branches/release27-maint/Lib/_abcoll.py	Tue Aug 24 23:09:30 2010
@@ -305,18 +305,24 @@
         return self
 
     def __ixor__(self, it):
-        if not isinstance(it, Set):
-            it = self._from_iterable(it)
-        for value in it:
-            if value in self:
-                self.discard(value)
-            else:
-                self.add(value)
+        if it is self:
+            self.clear()
+        else:
+            if not isinstance(it, Set):
+                it = self._from_iterable(it)
+            for value in it:
+                if value in self:
+                    self.discard(value)
+                else:
+                    self.add(value)
         return self
 
     def __isub__(self, it):
-        for value in it:
-            self.discard(value)
+        if it is self:
+            self.clear()
+        else:
+            for value in it:
+                self.discard(value)
         return self
 
 MutableSet.register(set)

Modified: python/branches/release27-maint/Lib/test/test_collections.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_collections.py	(original)
+++ python/branches/release27-maint/Lib/test/test_collections.py	Tue Aug 24 23:09:30 2010
@@ -526,6 +526,21 @@
         s = MySet([5,43,2,1])
         self.assertEqual(s.pop(), 1)
 
+    def test_issue8750(self):
+        empty = WithSet()
+        full = WithSet(range(10))
+        s = WithSet(full)
+        s -= s
+        self.assertEqual(s, empty)
+        s = WithSet(full)
+        s ^= s
+        self.assertEqual(s, empty)
+        s = WithSet(full)
+        s &= s
+        self.assertEqual(s, full)
+        s |= s
+        self.assertEqual(s, full)
+
     def test_Mapping(self):
         for sample in [dict]:
             self.assertIsInstance(sample(), Mapping)

Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Tue Aug 24 23:09:30 2010
@@ -31,6 +31,9 @@
 Library
 -------
 
+- Issue #8750: Fixed MutableSet's methods to correctly handle
+  reflexive operations, namely x -= x and x ^= x.
+
 - Issue #9129: smtpd.py is vulnerable to DoS attacks deriving from missing 
   error handling when accepting a new connection.
 


More information about the Python-checkins mailing list