Issue #29331: Simplified argument parsing in sorted() and list.sort().

This commit is contained in:
Serhiy Storchaka 2017-01-21 23:05:00 +02:00
parent 5e65cd39df
commit 7cf8bebb07
2 changed files with 19 additions and 23 deletions

View file

@ -2126,15 +2126,11 @@ PyDoc_STRVAR(builtin_sorted__doc__,
static PyObject *
builtin_sorted(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *newlist, *v, *seq, *keyfunc=NULL;
PyObject *callable;
static const char * const kwlist[] = {"", "key", "reverse", 0};
/* args 1-3 should match listsort in Objects/listobject.c */
static _PyArg_Parser parser = {"O|Oi:sorted", kwlist, 0};
int reverse;
PyObject *newlist, *v, *seq, *callable;
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &parser,
&seq, &keyfunc, &reverse))
/* Keyword arguments are passed through list.sort() which will check
them. */
if (!_PyArg_UnpackStack(args, nargs, "sorted", 1, 1, &seq))
return NULL;
newlist = PySequence_List(seq);