implement missing inequality on WeakSet

This commit is contained in:
Benjamin Peterson 2013-05-22 13:25:41 -07:00
parent 54f70923a3
commit 1cf48b4adc
3 changed files with 14 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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.