diff options
author | Zackery Spytz <zspytz@gmail.com> | 2021-04-02 15:28:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-02 15:28:35 (GMT) |
commit | afd12650580725ac598b2845384771c14c4f952e (patch) | |
tree | 2290e54eaa5fdb75d0b0513f0e575c440150fafd /Modules/clinic | |
parent | 240bcf82a11fe7433a61da70605e924c53b88096 (diff) | |
download | cpython-afd12650580725ac598b2845384771c14c4f952e.zip cpython-afd12650580725ac598b2845384771c14c4f952e.tar.gz cpython-afd12650580725ac598b2845384771c14c4f952e.tar.bz2 |
bpo-31956: Add start and stop parameters to array.index() (GH-25059)
Co-Authored-By: Anders Lorentsen <Phaqui@gmail.com>
Diffstat (limited to 'Modules/clinic')
-rw-r--r-- | Modules/clinic/arraymodule.c.h | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h index d0b70c4..d2513eb 100644 --- a/Modules/clinic/arraymodule.c.h +++ b/Modules/clinic/arraymodule.c.h @@ -39,13 +39,50 @@ PyDoc_STRVAR(array_array_count__doc__, {"count", (PyCFunction)array_array_count, METH_O, array_array_count__doc__}, PyDoc_STRVAR(array_array_index__doc__, -"index($self, v, /)\n" +"index($self, v, start=0, stop=sys.maxsize, /)\n" "--\n" "\n" -"Return index of first occurrence of v in the array."); +"Return index of first occurrence of v in the array.\n" +"\n" +"Raise ValueError if the value is not present."); #define ARRAY_ARRAY_INDEX_METHODDEF \ - {"index", (PyCFunction)array_array_index, METH_O, array_array_index__doc__}, + {"index", (PyCFunction)(void(*)(void))array_array_index, METH_FASTCALL, array_array_index__doc__}, + +static PyObject * +array_array_index_impl(arrayobject *self, PyObject *v, Py_ssize_t start, + Py_ssize_t stop); + +static PyObject * +array_array_index(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *v; + Py_ssize_t start = 0; + Py_ssize_t stop = PY_SSIZE_T_MAX; + + if (!_PyArg_CheckPositional("index", nargs, 1, 3)) { + goto exit; + } + v = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[1], &start)) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[2], &stop)) { + goto exit; + } +skip_optional: + return_value = array_array_index_impl(self, v, start, stop); + +exit: + return return_value; +} PyDoc_STRVAR(array_array_remove__doc__, "remove($self, v, /)\n" @@ -535,4 +572,4 @@ PyDoc_STRVAR(array_arrayiterator___setstate____doc__, #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, -/*[clinic end generated code: output=a7f71a18b994c88f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=376001addedc67ee input=a9049054013a1b77]*/ |