diff options
author | Raymond Hettinger <python@rcn.com> | 2016-05-05 08:14:06 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-05-05 08:14:06 (GMT) |
commit | 584e8aedc3d66721efcdcbd1a43d4c5b7476427b (patch) | |
tree | 55e0a4e70a641ef36665489fac95802d5fba3cb3 /Lib/test/test_collections.py | |
parent | d7062de95d035121abbab526c3b59904361aa256 (diff) | |
download | cpython-584e8aedc3d66721efcdcbd1a43d4c5b7476427b.zip cpython-584e8aedc3d66721efcdcbd1a43d4c5b7476427b.tar.gz cpython-584e8aedc3d66721efcdcbd1a43d4c5b7476427b.tar.bz2 |
Issue 26915: Add identity checks to the collections ABC __contains__ methods.
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r-- | Lib/test/test_collections.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 4202462..3824a87 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -23,7 +23,7 @@ from collections.abc import Awaitable, Coroutine, AsyncIterator, AsyncIterable from collections.abc import Hashable, Iterable, Iterator, Generator, Reversible from collections.abc import Sized, Container, Callable from collections.abc import Set, MutableSet -from collections.abc import Mapping, MutableMapping, KeysView, ItemsView +from collections.abc import Mapping, MutableMapping, KeysView, ItemsView, ValuesView from collections.abc import Sequence, MutableSequence from collections.abc import ByteString @@ -1074,6 +1074,26 @@ class TestCollectionABCs(ABCTestCase): self.assertFalse(ncs > cs) self.assertTrue(ncs >= cs) + def test_issue26915(self): + # Container membership test should check identity first + class CustomEqualObject: + def __eq__(self, other): + return False + class CustomSequence(list): + def __contains__(self, value): + return Sequence.__contains__(self, value) + + nan = float('nan') + obj = CustomEqualObject() + containers = [ + CustomSequence([nan, obj]), + ItemsView({1: nan, 2: obj}), + ValuesView({1: nan, 2: obj}) + ] + for container in containers: + for elem in container: + self.assertIn(elem, container) + def assertSameSet(self, s1, s2): # coerce both to a real set then check equality self.assertSetEqual(set(s1), set(s2)) |