Skip to content

Commit f0264db

Browse files
Optimize UserList type checks to use list directly
1 parent 6c4c045 commit f0264db

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Lib/collections/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ def __init__(self, initlist=None):
12861286
self.data = []
12871287
if initlist is not None:
12881288
# XXX should this accept an arbitrary sequence?
1289-
if type(initlist) == type(self.data):
1289+
if type(initlist) is list:
12901290
self.data[:] = initlist
12911291
elif isinstance(initlist, UserList):
12921292
self.data[:] = initlist.data[:]
@@ -1335,21 +1335,21 @@ def __delitem__(self, i):
13351335
def __add__(self, other):
13361336
if isinstance(other, UserList):
13371337
return self.__class__(self.data + other.data)
1338-
elif isinstance(other, type(self.data)):
1338+
elif isinstance(other, list):
13391339
return self.__class__(self.data + other)
13401340
return self.__class__(self.data + list(other))
13411341

13421342
def __radd__(self, other):
13431343
if isinstance(other, UserList):
13441344
return self.__class__(other.data + self.data)
1345-
elif isinstance(other, type(self.data)):
1345+
elif isinstance(other, list):
13461346
return self.__class__(other + self.data)
13471347
return self.__class__(list(other) + self.data)
13481348

13491349
def __iadd__(self, other):
13501350
if isinstance(other, UserList):
13511351
self.data += other.data
1352-
elif isinstance(other, type(self.data)):
1352+
elif isinstance(other, list):
13531353
self.data += other
13541354
else:
13551355
self.data += list(other)

0 commit comments

Comments
 (0)