implement missing inequality on WeakSet
This commit is contained in:
parent
54f70923a3
commit
1cf48b4adc
|
@ -171,6 +171,12 @@ class WeakSet(object):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
return self.data == set(ref(item) for item in other)
|
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):
|
def symmetric_difference(self, other):
|
||||||
newset = self.copy()
|
newset = self.copy()
|
||||||
newset.symmetric_difference_update(other)
|
newset.symmetric_difference_update(other)
|
||||||
|
|
|
@ -351,6 +351,12 @@ class TestWeakSet(unittest.TestCase):
|
||||||
self.assertFalse(self.s == tuple(self.items))
|
self.assertFalse(self.s == tuple(self.items))
|
||||||
self.assertFalse(self.s == 1)
|
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):
|
def test_weak_destroy_while_iterating(self):
|
||||||
# Issue #7105: iterators shouldn't crash when a key is implicitly removed
|
# Issue #7105: iterators shouldn't crash when a key is implicitly removed
|
||||||
# Create new items to be sure no-one else holds a reference
|
# Create new items to be sure no-one else holds a reference
|
||||||
|
|
|
@ -15,6 +15,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Implement inequality on weakref.WeakSet.
|
||||||
|
|
||||||
- Issue #17981: Closed socket on error in SysLogHandler.
|
- Issue #17981: Closed socket on error in SysLogHandler.
|
||||||
|
|
||||||
- Issue #17754: Make ctypes.util.find_library() independent of the locale.
|
- Issue #17754: Make ctypes.util.find_library() independent of the locale.
|
||||||
|
|
Loading…
Reference in New Issue