# HG changeset patch # User Julien Palard # Date 1479673004 -3600 # Sun Nov 20 21:16:44 2016 +0100 # Node ID 66b9a29d269684cf310b07f93d2517deaff09d9a # Parent 8a4eaab4eeb3c53d3e9c069aac8f62ba733ec416 Argument Clinic for bisect.bisect_left. diff -r 8a4eaab4eeb3 -r 66b9a29d2696 Modules/_bisectmodule.c --- a/Modules/_bisectmodule.c Sun Nov 20 11:33:15 2016 -0800 +++ b/Modules/_bisectmodule.c Sun Nov 20 21:16:44 2016 +0100 @@ -6,6 +6,13 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "clinic/_bisectmodule.c.h" + +/*[clinic input] +module bisect +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=d0e256c42a9e4c13]*/ + _Py_IDENTIFIER(insert); static Py_ssize_t @@ -148,36 +155,42 @@ return lo; } +/*[clinic input] +bisect.bisect_left + + a: 'O' + The list in which ``x`` is to be inserted. + x: 'O' + The value to be inserted. + lo: 'n' = 0 + Lower bound, defaults to 0. + hi: 'n' = -1 + Upper bound, defaults to -1 (meaning ``len(a)``). + +Return the index where to insert item x in list a, assuming a is sorted. + +The return value i is such that all e in a[:i] have e < x, and all e in +a[i:] have e >= x. So if x already appears in the list, i points just +before the leftmost x already there. + +Optional args lo (default 0) and hi (default len(a)) bound the +slice of a to be searched. + +[clinic start generated code]*/ + static PyObject * -bisect_left(PyObject *self, PyObject *args, PyObject *kw) +bisect_bisect_left_impl(PyObject *module, PyObject *a, PyObject *x, + Py_ssize_t lo, Py_ssize_t hi) +/*[clinic end generated code: output=27a0228c4a0a5fa2 input=da5d94d033fd82fc]*/ { - PyObject *list, *item; - Py_ssize_t lo = 0; - Py_ssize_t hi = -1; Py_ssize_t index; - static char *keywords[] = {"a", "x", "lo", "hi", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|nn:bisect_left", - keywords, &list, &item, &lo, &hi)) - return NULL; - index = internal_bisect_left(list, item, lo, hi); + index = internal_bisect_left(a, x, lo, hi); if (index < 0) return NULL; return PyLong_FromSsize_t(index); } -PyDoc_STRVAR(bisect_left_doc, -"bisect_left(a, x[, lo[, hi]]) -> index\n\ -\n\ -Return the index where to insert item x in list a, assuming a is sorted.\n\ -\n\ -The return value i is such that all e in a[:i] have e < x, and all e in\n\ -a[i:] have e >= x. So if x already appears in the list, i points just\n\ -before the leftmost x already there.\n\ -\n\ -Optional args lo (default 0) and hi (default len(a)) bound the\n\ -slice of a to be searched.\n"); - static PyObject * insort_left(PyObject *self, PyObject *args, PyObject *kw) { @@ -228,8 +241,7 @@ METH_VARARGS|METH_KEYWORDS, insort_right_doc}, {"insort", (PyCFunction)insort_right, METH_VARARGS|METH_KEYWORDS, insort_doc}, - {"bisect_left", (PyCFunction)bisect_left, - METH_VARARGS|METH_KEYWORDS, bisect_left_doc}, + BISECT_BISECT_LEFT_METHODDEF {"insort_left", (PyCFunction)insort_left, METH_VARARGS|METH_KEYWORDS, insort_left_doc}, {NULL, NULL} /* sentinel */