return other.data if isinstance(other, UserList) else other
def __contains__(self, item): return item in self.data
def __len__(self): return len(self.data)
- def __getitem__(self, i): return self.data[i]
+ def __getitem__(self, i):
+ if isinstance(i, slice):
+ return self.__class__(self.data[i])
+ else:
+ return self.data[i]
def __setitem__(self, i, item): self.data[i] = item
def __delitem__(self, i): del self.data[i]
def __add__(self, other):
for j in range(-3, 6):
self.assertEqual(u[i:j], l[i:j])
+ def test_slice_type(self):
+ l = [0, 1, 2, 3, 4]
+ u = UserList(l)
+ self.assertIsInstance(u[:], u.__class__)
+ self.assertEqual(u[:],u)
+
def test_add_specials(self):
u = UserList("spam")
u2 = u + "eggs"