diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-31 01:38:15 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-31 01:38:15 +0000 |
commit | e67420d72e26d976af2c8cd8603f2dfe158b6d24 (patch) | |
tree | 00709b01f876ef8d1ffe72bfe32acfc9f1c3d913 /Lib/_abcoll.py | |
parent | cba36bbe65c5df5d2a16d7780beceb2faefb6c75 (diff) | |
download | cpython-git-e67420d72e26d976af2c8cd8603f2dfe158b6d24.tar.gz |
Fix defect in __ixor__ which would get the wrong
answer if the input iterable had a duplicate element
(two calls to toggle() reverse each other). Borrow
the correct code from sets.py.
Diffstat (limited to 'Lib/_abcoll.py')
-rw-r--r-- | Lib/_abcoll.py | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py index e1e65106ce..75a8072528 100644 --- a/Lib/_abcoll.py +++ b/Lib/_abcoll.py @@ -266,16 +266,6 @@ class MutableSet(Set): self.discard(value) return value - def toggle(self, value): - """Return True if it was added, False if deleted.""" - # XXX This implementation is not thread-safe - if value in self: - self.discard(value) - return False - else: - self.add(value) - return True - def clear(self): """This is slow (creates N new iterators!) but effective.""" try: @@ -296,10 +286,13 @@ class MutableSet(Set): return self def __ixor__(self, it): - # This calls toggle(), so if that is overridded, we call the override + if not isinstance(it, Set): + it = self._from_iterable(it) for value in it: - self.toggle(it) - return self + if value in self: + self.discard(value) + else: + self.add(value) def __isub__(self, it): for value in it: |