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

Side by Side Diff: Lib/collections/__init__.py

Issue 22189: collections.UserString missing some str methods
Patch Set: Created 4 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') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 __all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict', 'UserList', 1 __all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict', 'UserList',
2 'UserString', 'Counter', 'OrderedDict', 'ChainMap'] 2 'UserString', 'Counter', 'OrderedDict', 'ChainMap']
3 3
4 # For backwards compatibility, continue to make the collections ABCs 4 # For backwards compatibility, continue to make the collections ABCs
5 # available through the collections module. 5 # available through the collections module.
6 from _collections_abc import * 6 from _collections_abc import *
7 import _collections_abc 7 import _collections_abc
8 __all__ += _collections_abc.__all__ 8 __all__ += _collections_abc.__all__
9 9
10 from _collections import deque, defaultdict 10 from _collections import deque, defaultdict
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 elif isinstance(seq, UserString): 1053 elif isinstance(seq, UserString):
1054 self.data = seq.data[:] 1054 self.data = seq.data[:]
1055 else: 1055 else:
1056 self.data = str(seq) 1056 self.data = str(seq)
1057 def __str__(self): return str(self.data) 1057 def __str__(self): return str(self.data)
1058 def __repr__(self): return repr(self.data) 1058 def __repr__(self): return repr(self.data)
1059 def __int__(self): return int(self.data) 1059 def __int__(self): return int(self.data)
1060 def __float__(self): return float(self.data) 1060 def __float__(self): return float(self.data)
1061 def __complex__(self): return complex(self.data) 1061 def __complex__(self): return complex(self.data)
1062 def __hash__(self): return hash(self.data) 1062 def __hash__(self): return hash(self.data)
1063 def __getnewargs__(self):
1064 return (self.data[:],)
1063 1065
1064 def __eq__(self, string): 1066 def __eq__(self, string):
1065 if isinstance(string, UserString): 1067 if isinstance(string, UserString):
1066 return self.data == string.data 1068 return self.data == string.data
1067 return self.data == string 1069 return self.data == string
1068 def __lt__(self, string): 1070 def __lt__(self, string):
1069 if isinstance(string, UserString): 1071 if isinstance(string, UserString):
1070 return self.data < string.data 1072 return self.data < string.data
1071 return self.data < string 1073 return self.data < string
1072 def __le__(self, string): 1074 def __le__(self, string):
(...skipping 24 matching lines...) Expand all
1097 return self.__class__(self.data + str(other)) 1099 return self.__class__(self.data + str(other))
1098 def __radd__(self, other): 1100 def __radd__(self, other):
1099 if isinstance(other, str): 1101 if isinstance(other, str):
1100 return self.__class__(other + self.data) 1102 return self.__class__(other + self.data)
1101 return self.__class__(str(other) + self.data) 1103 return self.__class__(str(other) + self.data)
1102 def __mul__(self, n): 1104 def __mul__(self, n):
1103 return self.__class__(self.data*n) 1105 return self.__class__(self.data*n)
1104 __rmul__ = __mul__ 1106 __rmul__ = __mul__
1105 def __mod__(self, args): 1107 def __mod__(self, args):
1106 return self.__class__(self.data % args) 1108 return self.__class__(self.data % args)
1109 def __rmod__(self, format):
1110 return self.__class__(format % args)
1107 1111
1108 # the following methods are defined in alphabetical order: 1112 # the following methods are defined in alphabetical order:
1109 def capitalize(self): return self.__class__(self.data.capitalize()) 1113 def capitalize(self): return self.__class__(self.data.capitalize())
1114 def casefold(self):
1115 return self.__class__(self.data.casefold())
1110 def center(self, width, *args): 1116 def center(self, width, *args):
1111 return self.__class__(self.data.center(width, *args)) 1117 return self.__class__(self.data.center(width, *args))
1112 def count(self, sub, start=0, end=_sys.maxsize): 1118 def count(self, sub, start=0, end=_sys.maxsize):
1113 if isinstance(sub, UserString): 1119 if isinstance(sub, UserString):
1114 sub = sub.data 1120 sub = sub.data
1115 return self.data.count(sub, start, end) 1121 return self.data.count(sub, start, end)
1116 def encode(self, encoding=None, errors=None): # XXX improve this? 1122 def encode(self, encoding=None, errors=None): # XXX improve this?
1117 if encoding: 1123 if encoding:
1118 if errors: 1124 if errors:
1119 return self.__class__(self.data.encode(encoding, errors)) 1125 return self.__class__(self.data.encode(encoding, errors))
1120 return self.__class__(self.data.encode(encoding)) 1126 return self.__class__(self.data.encode(encoding))
1121 return self.__class__(self.data.encode()) 1127 return self.__class__(self.data.encode())
1122 def endswith(self, suffix, start=0, end=_sys.maxsize): 1128 def endswith(self, suffix, start=0, end=_sys.maxsize):
1123 return self.data.endswith(suffix, start, end) 1129 return self.data.endswith(suffix, start, end)
1124 def expandtabs(self, tabsize=8): 1130 def expandtabs(self, tabsize=8):
1125 return self.__class__(self.data.expandtabs(tabsize)) 1131 return self.__class__(self.data.expandtabs(tabsize))
1126 def find(self, sub, start=0, end=_sys.maxsize): 1132 def find(self, sub, start=0, end=_sys.maxsize):
1127 if isinstance(sub, UserString): 1133 if isinstance(sub, UserString):
1128 sub = sub.data 1134 sub = sub.data
1129 return self.data.find(sub, start, end) 1135 return self.data.find(sub, start, end)
1130 def format(self, *args, **kwds): 1136 def format(self, *args, **kwds):
1131 return self.data.format(*args, **kwds) 1137 return self.data.format(*args, **kwds)
1138 def format_map(self, mapping):
1139 return self.data.format_map(mapping)
1132 def index(self, sub, start=0, end=_sys.maxsize): 1140 def index(self, sub, start=0, end=_sys.maxsize):
1133 return self.data.index(sub, start, end) 1141 return self.data.index(sub, start, end)
1134 def isalpha(self): return self.data.isalpha() 1142 def isalpha(self): return self.data.isalpha()
1135 def isalnum(self): return self.data.isalnum() 1143 def isalnum(self): return self.data.isalnum()
1136 def isdecimal(self): return self.data.isdecimal() 1144 def isdecimal(self): return self.data.isdecimal()
1137 def isdigit(self): return self.data.isdigit() 1145 def isdigit(self): return self.data.isdigit()
1138 def isidentifier(self): return self.data.isidentifier() 1146 def isidentifier(self): return self.data.isidentifier()
1139 def islower(self): return self.data.islower() 1147 def islower(self): return self.data.islower()
1140 def isnumeric(self): return self.data.isnumeric() 1148 def isnumeric(self): return self.data.isnumeric()
1149 def isprintable(self): return self.data.isprintable()
1141 def isspace(self): return self.data.isspace() 1150 def isspace(self): return self.data.isspace()
1142 def istitle(self): return self.data.istitle() 1151 def istitle(self): return self.data.istitle()
1143 def isupper(self): return self.data.isupper() 1152 def isupper(self): return self.data.isupper()
1144 def join(self, seq): return self.data.join(seq) 1153 def join(self, seq): return self.data.join(seq)
1145 def ljust(self, width, *args): 1154 def ljust(self, width, *args):
1146 return self.__class__(self.data.ljust(width, *args)) 1155 return self.__class__(self.data.ljust(width, *args))
1147 def lower(self): return self.__class__(self.data.lower()) 1156 def lower(self): return self.__class__(self.data.lower())
1148 def lstrip(self, chars=None): return self.__class__(self.data.lstrip(chars)) 1157 def lstrip(self, chars=None): return self.__class__(self.data.lstrip(chars))
1158 maketrans = str.maketrans
1149 def partition(self, sep): 1159 def partition(self, sep):
1150 return self.data.partition(sep) 1160 return self.data.partition(sep)
1151 def replace(self, old, new, maxsplit=-1): 1161 def replace(self, old, new, maxsplit=-1):
1152 if isinstance(old, UserString): 1162 if isinstance(old, UserString):
1153 old = old.data 1163 old = old.data
1154 if isinstance(new, UserString): 1164 if isinstance(new, UserString):
1155 new = new.data 1165 new = new.data
1156 return self.__class__(self.data.replace(old, new, maxsplit)) 1166 return self.__class__(self.data.replace(old, new, maxsplit))
1157 def rfind(self, sub, start=0, end=_sys.maxsize): 1167 def rfind(self, sub, start=0, end=_sys.maxsize):
1158 if isinstance(sub, UserString): 1168 if isinstance(sub, UserString):
(...skipping 14 matching lines...) Expand all
1173 def splitlines(self, keepends=False): return self.data.splitlines(keepends) 1183 def splitlines(self, keepends=False): return self.data.splitlines(keepends)
1174 def startswith(self, prefix, start=0, end=_sys.maxsize): 1184 def startswith(self, prefix, start=0, end=_sys.maxsize):
1175 return self.data.startswith(prefix, start, end) 1185 return self.data.startswith(prefix, start, end)
1176 def strip(self, chars=None): return self.__class__(self.data.strip(chars)) 1186 def strip(self, chars=None): return self.__class__(self.data.strip(chars))
1177 def swapcase(self): return self.__class__(self.data.swapcase()) 1187 def swapcase(self): return self.__class__(self.data.swapcase())
1178 def title(self): return self.__class__(self.data.title()) 1188 def title(self): return self.__class__(self.data.title())
1179 def translate(self, *args): 1189 def translate(self, *args):
1180 return self.__class__(self.data.translate(*args)) 1190 return self.__class__(self.data.translate(*args))
1181 def upper(self): return self.__class__(self.data.upper()) 1191 def upper(self): return self.__class__(self.data.upper())
1182 def zfill(self, width): return self.__class__(self.data.zfill(width)) 1192 def zfill(self, width): return self.__class__(self.data.zfill(width))
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_collections.py » ('j') | no next file with comments »

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