diff options
author | Raymond Hettinger <python@rcn.com> | 2009-04-01 18:50:56 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-04-01 18:50:56 +0000 |
commit | 66c4a6b51cea40215e8f61e1abe2e3d89c4aeb1e (patch) | |
tree | 9514206018d91419cad25cdfdc9f8f4084270935 /Lib/test | |
parent | 449b7d95d46f0b2e8a1fd73642d391ac3a29518e (diff) | |
download | cpython-git-66c4a6b51cea40215e8f61e1abe2e3d89c4aeb1e.tar.gz |
Issue #5647: MutableSet.__iand__() no longer mutates self during iteration.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_collections.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 9e984ba930..8ffa75bdc5 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -327,6 +327,25 @@ class TestOneTrickPonyABCs(ABCTestCase): B.register(C) self.failUnless(issubclass(C, B)) +class WithSet(MutableSet): + + def __init__(self, it=()): + self.data = set(it) + + def __len__(self): + return len(self.data) + + def __iter__(self): + return iter(self.data) + + def __contains__(self, item): + return item in self.data + + def add(self, item): + self.data.add(item) + + def discard(self, item): + self.data.discard(item) class TestCollectionABCs(ABCTestCase): @@ -363,6 +382,12 @@ class TestCollectionABCs(ABCTestCase): self.validate_abstract_methods(MutableSet, '__contains__', '__iter__', '__len__', 'add', 'discard') + def test_issue_5647(self): + # MutableSet.__iand__ mutated the set during iteration + s = WithSet('abcd') + s &= WithSet('cdef') # This used to fail + self.assertEqual(set(s), set('cd')) + def test_issue_4920(self): # MutableSet.pop() method did not work class MySet(collections.MutableSet): |