diff -r c941a85f5169 Modules/_bisectmodule.c --- a/Modules/_bisectmodule.c Sun Nov 20 22:21:55 2016 +0100 +++ b/Modules/_bisectmodule.c Sun Nov 20 22:25:18 2016 +0100 @@ -252,26 +252,43 @@ return PyLong_FromSsize_t(index); } +/*[clinic input] +bisect.insort_left + + a: 'O' + The list in which ``x`` will be inserted. + x: 'O' + The value to insert. + lo: 'n' = 0 + Lower bound, defaults to 0. + hi: 'n' = -1 + Upper bound, defaults to -1 (meaning ``len(a)``). + +Insert item x in list a, and keep it sorted assuming a is sorted. + +If x is already in a, insert it to the left of the leftmost x. + +Optional args lo (default 0) and hi (default len(a)) bound the +slice of a to be searched. + +[clinic start generated code]*/ + static PyObject * -insort_left(PyObject *self, PyObject *args, PyObject *kw) +bisect_insort_left_impl(PyObject *module, PyObject *a, PyObject *x, + Py_ssize_t lo, Py_ssize_t hi) +/*[clinic end generated code: output=aa0228af6970ec52 input=aa95f626a96be30a]*/ { - PyObject *list, *item, *result; - Py_ssize_t lo = 0; - Py_ssize_t hi = -1; + PyObject *result; Py_ssize_t index; - static char *keywords[] = {"a", "x", "lo", "hi", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|nn:insort_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; - if (PyList_CheckExact(list)) { - if (PyList_Insert(list, index, item) < 0) + if (PyList_CheckExact(a)) { + if (PyList_Insert(a, index, x) < 0) return NULL; } else { - result = _PyObject_CallMethodId(list, &PyId_insert, "nO", index, item); + result = _PyObject_CallMethodId(a, &PyId_insert, "nO", index, x); if (result == NULL) return NULL; Py_DECREF(result); @@ -280,24 +297,13 @@ Py_RETURN_NONE; } -PyDoc_STRVAR(insort_left_doc, -"insort_left(a, x[, lo[, hi]])\n\ -\n\ -Insert item x in list a, and keep it sorted assuming a is sorted.\n\ -\n\ -If x is already in a, insert it to the left of the leftmost x.\n\ -\n\ -Optional args lo (default 0) and hi (default len(a)) bound the\n\ -slice of a to be searched.\n"); - static PyMethodDef bisect_methods[] = { BISECT_BISECT_RIGHT_METHODDEF BISECT_BISECT_METHODDEF BISECT_INSORT_RIGHT_METHODDEF BISECT_INSORT_METHODDEF BISECT_BISECT_LEFT_METHODDEF - {"insort_left", (PyCFunction)insort_left, - METH_VARARGS|METH_KEYWORDS, insort_left_doc}, + BISECT_INSORT_LEFT_METHODDEF {NULL, NULL} /* sentinel */ };