[Python-checkins] cpython (2.7): implement missing inequality on WeakSet

benjamin.peterson python-checkins at python.org
Wed May 22 22:27:47 CEST 2013


http://hg.python.org/cpython/rev/fa9c0c651f78
changeset:   83893:fa9c0c651f78
branch:      2.7
parent:      83887:85c04fdaa404
user:        Benjamin Peterson <benjamin at python.org>
date:        Wed May 22 13:25:41 2013 -0700
summary:
  implement missing inequality on WeakSet

files:
  Lib/_weakrefset.py       |  6 ++++++
  Lib/test/test_weakset.py |  6 ++++++
  Misc/NEWS                |  2 ++
  3 files changed, 14 insertions(+), 0 deletions(-)


diff --git a/Lib/_weakrefset.py b/Lib/_weakrefset.py
--- a/Lib/_weakrefset.py
+++ b/Lib/_weakrefset.py
@@ -171,6 +171,12 @@
             return NotImplemented
         return self.data == set(ref(item) for item in other)
 
+    def __ne__(self, other):
+        opposite = self.__eq__(other)
+        if opposite is NotImplemented:
+            return NotImplemented
+        return not opposite
+
     def symmetric_difference(self, other):
         newset = self.copy()
         newset.symmetric_difference_update(other)
diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py
--- a/Lib/test/test_weakset.py
+++ b/Lib/test/test_weakset.py
@@ -351,6 +351,12 @@
         self.assertFalse(self.s == tuple(self.items))
         self.assertFalse(self.s == 1)
 
+    def test_ne(self):
+        self.assertTrue(self.s != set(self.items))
+        s1 = WeakSet()
+        s2 = WeakSet()
+        self.assertFalse(s1 != s2)
+
     def test_weak_destroy_while_iterating(self):
         # Issue #7105: iterators shouldn't crash when a key is implicitly removed
         # Create new items to be sure no-one else holds a reference
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,8 @@
 Library
 -------
 
+- Implement inequality on weakref.WeakSet.
+
 - Issue #17981: Closed socket on error in SysLogHandler.
 
 - Issue #17754: Make ctypes.util.find_library() independent of the locale.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list