diff options
author | Daniel Stutzbach <daniel@stutzbachenterprises.com> | 2010-08-24 20:49:57 (GMT) |
---|---|---|
committer | Daniel Stutzbach <daniel@stutzbachenterprises.com> | 2010-08-24 20:49:57 (GMT) |
commit | 31da5b2f69d408ac2448eb04ee2892b8aa3aac79 (patch) | |
tree | ea3f9ab6d296e9a7b265544b1244c734d967b334 /Lib/_abcoll.py | |
parent | d8e5f2df68c85f7a26e34a57f8f3f791c30a688f (diff) | |
download | cpython-31da5b2f69d408ac2448eb04ee2892b8aa3aac79.zip cpython-31da5b2f69d408ac2448eb04ee2892b8aa3aac79.tar.gz cpython-31da5b2f69d408ac2448eb04ee2892b8aa3aac79.tar.bz2 |
Issue 8750: Fixed MutableSet's methods to correctly handle reflexive operations, namely x -= x and x ^= x
Diffstat (limited to 'Lib/_abcoll.py')
-rw-r--r-- | Lib/_abcoll.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py index d3e23c1..cac06e0 100644 --- a/Lib/_abcoll.py +++ b/Lib/_abcoll.py @@ -321,18 +321,24 @@ class MutableSet(Set): return self def __ixor__(self, it: Iterable): - if not isinstance(it, Set): - it = self._from_iterable(it) - for value in it: - if value in self: - self.discard(value) - else: - self.add(value) + if it is self: + self.clear() + else: + if not isinstance(it, Set): + it = self._from_iterable(it) + for value in it: + if value in self: + self.discard(value) + else: + self.add(value) return self def __isub__(self, it: Iterable): - for value in it: - self.discard(value) + if it is self: + self.clear() + else: + for value in it: + self.discard(value) return self MutableSet.register(set) |