implement missing inequality on WeakSet
This commit is contained in:
parent
54f70923a3
commit
1cf48b4adc
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue