Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be9733a

Browse files
committed
gh-114894: add array.array.clear() method
1 parent 1aec064 commit be9733a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Modules/arraymodule.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,20 @@ array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
868868
return (PyObject *)np;
869869
}
870870

871+
/*[clinic input]
872+
array.array.clear
873+
874+
Remove all items from the array.
875+
[clinic start generated code]*/
876+
877+
static PyObject *
878+
array_array_clear_impl(arrayobject *self)
879+
/*[clinic end generated code: output=5efe0417062210a9 input=5dffa30e94e717a4]*/
880+
{
881+
if (array_resize(self, 0) == -1)
882+
return NULL;
883+
Py_RETURN_NONE;
884+
}
871885

872886
/*[clinic input]
873887
array.array.__copy__
@@ -2342,6 +2356,7 @@ static PyMethodDef array_methods[] = {
23422356
ARRAY_ARRAY_APPEND_METHODDEF
23432357
ARRAY_ARRAY_BUFFER_INFO_METHODDEF
23442358
ARRAY_ARRAY_BYTESWAP_METHODDEF
2359+
ARRAY_ARRAY_CLEAR_METHODDEF
23452360
ARRAY_ARRAY___COPY___METHODDEF
23462361
ARRAY_ARRAY_COUNT_METHODDEF
23472362
ARRAY_ARRAY___DEEPCOPY___METHODDEF

Modules/clinic/arraymodule.c.h

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)