MCPcopy Index your code
hub / github.com/python/cpython / UserList

Class UserList

Lib/collections/__init__.py:1268–1394  ·  view source on GitHub ↗

A more or less complete user-defined wrapper around list objects.

Source from the content-addressed store, hash-verified

1266################################################################################
1267
1268class UserList(_collections_abc.MutableSequence):
1269 """A more or less complete user-defined wrapper around list objects."""
1270
1271 def __init__(self, initlist=None):
1272 self.data = []
1273 if initlist is not None:
1274 # XXX should this accept an arbitrary sequence?
1275 if type(initlist) == type(self.data):
1276 self.data[:] = initlist
1277 elif isinstance(initlist, UserList):
1278 self.data[:] = initlist.data[:]
1279 else:
1280 self.data = list(initlist)
1281
1282 def __repr__(self):
1283 return repr(self.data)
1284
1285 def __lt__(self, other):
1286 return self.data < self.__cast(other)
1287
1288 def __le__(self, other):
1289 return self.data <= self.__cast(other)
1290
1291 def __eq__(self, other):
1292 return self.data == self.__cast(other)
1293
1294 def __gt__(self, other):
1295 return self.data > self.__cast(other)
1296
1297 def __ge__(self, other):
1298 return self.data >= self.__cast(other)
1299
1300 def __cast(self, other):
1301 return other.data if isinstance(other, UserList) else other
1302
1303 def __contains__(self, item):
1304 return item in self.data
1305
1306 def __len__(self):
1307 return len(self.data)
1308
1309 def __getitem__(self, i):
1310 if isinstance(i, slice):
1311 return self.__class__(self.data[i])
1312 else:
1313 return self.data[i]
1314
1315 def __setitem__(self, i, item):
1316 self.data[i] = item
1317
1318 def __delitem__(self, i):
1319 del self.data[i]
1320
1321 def __add__(self, other):
1322 if isinstance(other, UserList):
1323 return self.__class__(self.data + other.data)
1324 elif isinstance(other, type(self.data)):
1325 return self.__class__(self.data + other)

Callers 15

test_precomputedMethod · 0.90
test_vsBuiltinSortMethod · 0.90
test_joinMethod · 0.90
test_list_copyMethod · 0.90
test_dataMethod · 0.90
test_slice_typeMethod · 0.90
test_mixed_addMethod · 0.90
test_mixed_iaddMethod · 0.90
test_implementationMethod · 0.90
test_recursionMethod · 0.90
test_list_check_exactMethod · 0.90
test_list_sizeMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_precomputedMethod · 0.72
test_vsBuiltinSortMethod · 0.72
test_joinMethod · 0.72
test_list_copyMethod · 0.72
test_dataMethod · 0.72
test_slice_typeMethod · 0.72
test_mixed_addMethod · 0.72
test_mixed_iaddMethod · 0.72
test_implementationMethod · 0.72
test_recursionMethod · 0.72
test_list_check_exactMethod · 0.72
test_list_sizeMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…