Author: Matthew Miller <[email protected]>
Branch: py3.3
Changeset: r70638:ced27c96f4c8
Date: 2014-04-14 16:58 -0400
http://bitbucket.org/pypy/pypy/changeset/ced27c96f4c8/

Log:    Add missing list copy function to fix test_list for Python 3

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -1841,6 +1841,7 @@
 
     sort = interp2app(W_ListObject.descr_sort),
     index = interp2app(W_ListObject.descr_index),
+    copy = interp2app(W_ListObject.clone),
     append = interp2app(W_ListObject.append),
     reverse = interp2app(W_ListObject.descr_reverse),
     __reversed__ = interp2app(W_ListObject.descr_reversed),
diff --git a/pypy/objspace/std/test/test_listobject.py 
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -1059,6 +1059,32 @@
         l.append(l)
         assert repr(l) == '[[...]]'
 
+    def test_copy(self):
+        # test that empty list copies the empty list
+        l = []
+        c = l.copy()
+        assert c == []
+
+        # test that the items of a list are the same
+        l = list(range(3))
+        c = l.copy()
+        assert l == c
+
+        # test that it's indeed a copy and not a reference
+        l = ['a', 'b']
+        c = l.copy()
+        c.append('i')
+        assert l == ['a', 'b']
+        assert c == l + ['i']
+
+        # test that it's a shallow, not a deep copy
+        l = [1, 2, [3, 4], 5]
+        c = l.copy()
+        assert l == c
+        assert c[3] == l[3]
+
+        raises(TypeError, l.copy, None)
+
     def test_append(self):
         l = []
         l.append('X')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to