Kaydet (Commit) 31da5b2f authored tarafından Daniel Stutzbach's avatar Daniel Stutzbach

Issue 8750: Fixed MutableSet's methods to correctly handle reflexive operations,…

Issue 8750: Fixed MutableSet's methods to correctly handle reflexive operations, namely x -= x and x ^= x
üst d8e5f2df
...@@ -321,18 +321,24 @@ class MutableSet(Set): ...@@ -321,18 +321,24 @@ class MutableSet(Set):
return self return self
def __ixor__(self, it: Iterable): def __ixor__(self, it: Iterable):
if not isinstance(it, Set): if it is self:
it = self._from_iterable(it) self.clear()
for value in it: else:
if value in self: if not isinstance(it, Set):
self.discard(value) it = self._from_iterable(it)
else: for value in it:
self.add(value) if value in self:
self.discard(value)
else:
self.add(value)
return self return self
def __isub__(self, it: Iterable): def __isub__(self, it: Iterable):
for value in it: if it is self:
self.discard(value) self.clear()
else:
for value in it:
self.discard(value)
return self return self
MutableSet.register(set) MutableSet.register(set)
......
...@@ -526,6 +526,21 @@ class TestCollectionABCs(ABCTestCase): ...@@ -526,6 +526,21 @@ class TestCollectionABCs(ABCTestCase):
s = MySet([5,43,2,1]) s = MySet([5,43,2,1])
self.assertEqual(s.pop(), 1) self.assertEqual(s.pop(), 1)
def test_issue8750(self):
empty = WithSet()
full = WithSet(range(10))
s = WithSet(full)
s -= s
self.assertEqual(s, empty)
s = WithSet(full)
s ^= s
self.assertEqual(s, empty)
s = WithSet(full)
s &= s
self.assertEqual(s, full)
s |= s
self.assertEqual(s, full)
def test_Mapping(self): def test_Mapping(self):
for sample in [dict]: for sample in [dict]:
self.assertIsInstance(sample(), Mapping) self.assertIsInstance(sample(), Mapping)
......
...@@ -126,6 +126,9 @@ Extensions ...@@ -126,6 +126,9 @@ Extensions
Library Library
------- -------
- Issue #8750: Fixed MutableSet's methods to correctly handle
reflexive operations, namely x -= x and x ^= x.
- Issue #9129: smtpd.py is vulnerable to DoS attacks deriving from missing - Issue #9129: smtpd.py is vulnerable to DoS attacks deriving from missing
error handling when accepting a new connection. error handling when accepting a new connection.
......
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