Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Side by Side Diff: Lib/_collections_abc.py

Issue 26915: Test identity first in membership operation of ItemsView, ValuesView and Sequence in collections.abc
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_collections.py » ('j') | Lib/test/test_collections.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2007 Google, Inc. All Rights Reserved. 1 # Copyright 2007 Google, Inc. All Rights Reserved.
2 # Licensed to PSF under a Contributor Agreement. 2 # Licensed to PSF under a Contributor Agreement.
3 3
4 """Abstract Base Classes (ABCs) for collections, according to PEP 3119. 4 """Abstract Base Classes (ABCs) for collections, according to PEP 3119.
5 5
6 Unit tests are in test_collections. 6 Unit tests are in test_collections.
7 """ 7 """
8 8
9 from abc import ABCMeta, abstractmethod 9 from abc import ABCMeta, abstractmethod
10 import sys 10 import sys
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 Raises ValueError if the value is not present. 853 Raises ValueError if the value is not present.
854 ''' 854 '''
855 if start is not None and start < 0: 855 if start is not None and start < 0:
856 start = max(len(self) + start, 0) 856 start = max(len(self) + start, 0)
857 if stop is not None and stop < 0: 857 if stop is not None and stop < 0:
858 stop += len(self) 858 stop += len(self)
859 859
860 i = start 860 i = start
861 while stop is None or i < stop: 861 while stop is None or i < stop:
862 try: 862 try:
863 if self[i] == value: 863 v = self[i]
864 if v is value or v == value:
864 return i 865 return i
865 except IndexError: 866 except IndexError:
866 break 867 break
867 i += 1 868 i += 1
868 raise ValueError 869 raise ValueError
869 870
870 def count(self, value): 871 def count(self, value):
871 'S.count(value) -> integer -- return number of occurrences of value' 872 'S.count(value) -> integer -- return number of occurrences of value'
872 return sum(1 for v in self if v == value) 873 return sum(1 for v in self if v is value or v == value)
873 874
874 Sequence.register(tuple) 875 Sequence.register(tuple)
875 Sequence.register(str) 876 Sequence.register(str)
876 Sequence.register(range) 877 Sequence.register(range)
877 Sequence.register(memoryview) 878 Sequence.register(memoryview)
878 879
879 880
880 class ByteString(Sequence): 881 class ByteString(Sequence):
881 882
882 """This unifies bytes and bytearray. 883 """This unifies bytes and bytearray.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 Raise ValueError if the value is not present. 951 Raise ValueError if the value is not present.
951 ''' 952 '''
952 del self[self.index(value)] 953 del self[self.index(value)]
953 954
954 def __iadd__(self, values): 955 def __iadd__(self, values):
955 self.extend(values) 956 self.extend(values)
956 return self 957 return self
957 958
958 MutableSequence.register(list) 959 MutableSequence.register(list)
959 MutableSequence.register(bytearray) # Multiply inheriting, see ByteString 960 MutableSequence.register(bytearray) # Multiply inheriting, see ByteString
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_collections.py » ('j') | Lib/test/test_collections.py » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+