diff --git a/pythran/pythonic/include/types/list.hpp b/pythran/pythonic/include/types/list.hpp index a4204c7f0..7c3cd20e5 100644 --- a/pythran/pythonic/include/types/list.hpp +++ b/pythran/pythonic/include/types/list.hpp @@ -341,6 +341,7 @@ namespace types iterator erase(size_t n); T pop(long x = -1); + void clear(); // TODO: have to raise a valueError none_type remove(T const &x); diff --git a/pythran/pythonic/types/list.hpp b/pythran/pythonic/types/list.hpp index 9e8930486..95092ed32 100644 --- a/pythran/pythonic/types/list.hpp +++ b/pythran/pythonic/types/list.hpp @@ -580,6 +580,14 @@ namespace types erase(x); return res; } + template + void list::clear() + { + long sz = size(); + for (long ii=0;ii none_type list::remove(T const &x) diff --git a/pythran/tables.py b/pythran/tables.py index 303e0300a..d1d20278b 100644 --- a/pythran/tables.py +++ b/pythran/tables.py @@ -195,6 +195,7 @@ def update_effects(self, node): "count": ConstMethodIntr(signature=Fun[[List[T0], T0], int]), "remove": MethodIntr(signature=Fun[[List[T0], T0], None]), "insert": MethodIntr(signature=Fun[[List[T0], int, T0], None]), + "clear": MethodIntr(signature=Fun[[List[T0]], None]), }, "slice": { "start": AttributeIntr(signature=Fun[[T0], int]), diff --git a/pythran/tests/test_list.py b/pythran/tests/test_list.py index e8b120f82..0d34005d6 100644 --- a/pythran/tests/test_list.py +++ b/pythran/tests/test_list.py @@ -25,6 +25,9 @@ def test_index_(self): def test_index_tuple(self): self.run_test("def index_tuple(a):\n b=[1,2,3,8,7,4]\n return tuple(b).index(a)", 1, index_tuple=[int]) + def test_clear_(self): + self.run_test("def clear_():\n b=[1,3,4,5,6,7]\n b.clear()\n return b", clear_=[]) + def test_pop_(self): self.run_test("def pop_(a):\n b=[1,3,4,5,6,7]\n return b.pop(a)", 2, pop_=[int])