summaryrefslogtreecommitdiffstats
path: root/Lib/_collections_abc.py
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2017-03-08 03:04:24 (GMT)
committerGitHub <noreply@github.com>2017-03-08 03:04:24 (GMT)
commitd5d3249e8a37936d32266fa06ac20017307a1f70 (patch)
tree93cc04b3e6be8772aa9afec42ed4765505f5ebd8 /Lib/_collections_abc.py
parent8f6b344d368c15c3fe56c65c2f2776e7766fef55 (diff)
downloadcpython-d5d3249e8a37936d32266fa06ac20017307a1f70.zip
cpython-d5d3249e8a37936d32266fa06ac20017307a1f70.tar.gz
cpython-d5d3249e8a37936d32266fa06ac20017307a1f70.tar.bz2
bpo-26915: Test identity first in membership operation in index() and count() methods of collections.abc.Sequence (GH-503)
Diffstat (limited to 'Lib/_collections_abc.py')
-rw-r--r--Lib/_collections_abc.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index b172f3f..005d884 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -908,7 +908,8 @@ class Sequence(Reversible, Collection):
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
@@ -917,7 +918,7 @@ class Sequence(Reversible, Collection):
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)