diff -r 75dc64c8c22b Lib/_collections_abc.py --- a/Lib/_collections_abc.py Wed Jun 01 08:17:27 2016 +0000 +++ b/Lib/_collections_abc.py Sat Jun 04 16:30:22 2016 +0800 @@ -860,7 +860,8 @@ i = start while stop is None or i < stop: try: - if self[i] == value: + v = self[i] + if v is value or v == value: return i except IndexError: break @@ -869,7 +870,7 @@ def count(self, value): 'S.count(value) -> integer -- return number of occurrences of value' - return sum(1 for v in self if v == value) + return sum(1 for v in self if v is value or v == value) Sequence.register(tuple) Sequence.register(str) diff -r 75dc64c8c22b Lib/test/test_collections.py --- a/Lib/test/test_collections.py Wed Jun 01 08:17:27 2016 +0000 +++ b/Lib/test/test_collections.py Sat Jun 04 16:30:22 2016 +0800 @@ -1079,20 +1079,30 @@ class CustomEqualObject: def __eq__(self, other): return False - class CustomSequence(list): - def __contains__(self, value): - return Sequence.__contains__(self, value) + class CustomSequence(Sequence): + def __init__(self, seq): + self._seq = seq + def __getitem__(self, index): + return self._seq[index] + def __len__(self, index): + return len(self._seq) nan = float('nan') obj = CustomEqualObject() + seq = CustomSequence([nan, obj, nan]) containers = [ - CustomSequence([nan, obj]), + seq, ItemsView({1: nan, 2: obj}), ValuesView({1: nan, 2: obj}) ] for container in containers: for elem in container: self.assertIn(elem, container) + self.assertEqual(seq.index(nan), 0) + self.assertNotEqual(seq.index(nan), 1) + self.assertEqual(seq.index(obj), 1) + self.assertEqual(seq.count(nan), 2) + self.assertEqual(seq.count(obj), 1) def assertSameSet(self, s1, s2): # coerce both to a real set then check equality