Commit 1cf48b4a authored by Benjamin Peterson's avatar Benjamin Peterson

implement missing inequality on WeakSet

parent 54f70923
......@@ -171,6 +171,12 @@ class WeakSet(object):
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)
......
......@@ -351,6 +351,12 @@ class TestWeakSet(unittest.TestCase):
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
......
......@@ -15,6 +15,8 @@ Core and Builtins
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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment