Author: Kurt Griffiths <[email protected]>
Branch: py3.3
Changeset: r70634:69693d4fab30
Date: 2014-04-14 17:08 -0400
http://bitbucket.org/pypy/pypy/changeset/69693d4fab30/
Log: Implement list.clear method
This patch simply adds descr_clear to W_ListObject and has it call
the internal clear() method.
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
@@ -588,6 +588,10 @@
raise OperationError(space.w_IndexError,
space.wrap("pop index out of range"))
+ def descr_clear(self, space):
+ '''L.clear() -- remove all items'''
+ self.clear(space)
+
def descr_remove(self, space, w_value):
'L.remove(value) -- remove first occurrence of value'
# needs to be safe against eq_w() mutating the w_list behind our back
@@ -1846,6 +1850,7 @@
__reversed__ = interp2app(W_ListObject.descr_reversed),
count = interp2app(W_ListObject.descr_count),
pop = interp2app(W_ListObject.descr_pop),
+ clear = interp2app(W_ListObject.descr_clear),
extend = interp2app(W_ListObject.extend),
insert = interp2app(W_ListObject.descr_insert),
remove = interp2app(W_ListObject.descr_remove),
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
@@ -814,7 +814,25 @@
l = [1.1, 2.2]
del l[:]
assert l == []
-
+
+ def test_clear(self):
+ l = l0 = [1,2,3]
+ l.clear()
+ assert l is l0
+ assert l == []
+
+ l = ['a', 'b']
+ l.clear()
+ assert l == []
+
+ l = [1.1, 2.2]
+ l.clear()
+ assert l == []
+
+ l = []
+ l.clear()
+ assert l == []
+
def test_iadd(self):
l = l0 = [1,2,3]
l += [4,5]
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit