From 584e8aedc3d66721efcdcbd1a43d4c5b7476427b Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 5 May 2016 11:14:06 +0300 Subject: Issue 26915: Add identity checks to the collections ABC __contains__ methods. --- Lib/_collections_abc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Lib/_collections_abc.py') diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index d3375847e2..31583731fc 100644 --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -689,7 +689,7 @@ class ItemsView(MappingView, Set): except KeyError: return False else: - return v == value + return v is value or v == value def __iter__(self): for key in self._mapping: @@ -704,7 +704,8 @@ class ValuesView(MappingView): def __contains__(self, value): for key in self._mapping: - if value == self._mapping[key]: + v = self._mapping[key] + if v is value or v == value: return True return False @@ -839,7 +840,7 @@ class Sequence(Sized, Reversible, Container): def __contains__(self, value): for v in self: - if v == value: + if v is value or v == value: return True return False -- cgit v1.2.1