]> granicus.if.org Git - python/commitdiff
Userlist.copy() wasn't returning a UserList.
authorRaymond Hettinger <python@rcn.com>
Thu, 5 May 2011 21:34:35 +0000 (14:34 -0700)
committerRaymond Hettinger <python@rcn.com>
Thu, 5 May 2011 21:34:35 +0000 (14:34 -0700)
Lib/collections/__init__.py
Lib/test/test_userlist.py

index 53e3dd7fa2b2c7d6aad20d4a4865e5a6f6c75064..4b447ace34d3bf29a464d388937e826e437a4571 100644 (file)
@@ -887,7 +887,7 @@ class UserList(MutableSequence):
     def pop(self, i=-1): return self.data.pop(i)
     def remove(self, item): self.data.remove(item)
     def clear(self): self.data.clear()
-    def copy(self): return self.data.copy()
+    def copy(self): return self.__class__(self)
     def count(self, item): return self.data.count(item)
     def index(self, item, *args): return self.data.index(item, *args)
     def reverse(self): self.data.reverse()
index 868ed24cccda59bd014b64e3aedd5fe71da7c5d9..6381070f56a163174cb5f458ead4d7d7e2a9d367 100644 (file)
@@ -52,6 +52,12 @@ class UserListTest(list_tests.CommonTest):
                 return str(key) + '!!!'
         self.assertEqual(next(iter(T((1,2)))), "0!!!")
 
+    def test_userlist_copy(self):
+        u = self.type2test([6, 8, 1, 9, 1])
+        v = u.copy()
+        self.assertEqual(u, v)
+        self.assertEqual(type(u), type(v))
+
 def test_main():
     support.run_unittest(UserListTest)