@@ -935,12 +935,16 @@ _functools_cmp_to_key_impl(PyObject *module, PyObject *mycmp)
935935// Not converted to argument clinic, because of `args` in-place modification. 
936936// AC will affect performance. 
937937static  PyObject  * 
938- functools_reduce (PyObject  * self , PyObject  * args )
938+ functools_reduce (PyObject  * self , PyObject  * args ,  PyObject   * kwargs )
939939{
940940    PyObject  * seq , * func , * result  =  NULL , * it ;
941+     static  char  * keywords [] =  {"" , "" , "initial" , NULL };
941942
942-     if  (!PyArg_UnpackTuple (args , "reduce" , 2 , 3 , & func , & seq , & result ))
943+     if  (!PyArg_ParseTupleAndKeywords (args , kwargs , "OO|O:reduce" , keywords ,
944+                                      & func , & seq , & result )) {
943945        return  NULL ;
946+     }
947+ 
944948    if  (result  !=  NULL )
945949        Py_INCREF (result );
946950
@@ -1007,7 +1011,7 @@ functools_reduce(PyObject *self, PyObject *args)
10071011}
10081012
10091013PyDoc_STRVAR (functools_reduce_doc ,
1010- "reduce(function, iterable[, initial], / ) -> value\n\ 
1014+ "reduce(function, iterable, / [, initial]) -> value\n\ 
10111015\n\ 
10121016Apply a function of two arguments cumulatively to the items of a sequence\n\ 
10131017or iterable, from left to right, so as to reduce the iterable to a single\n\ 
@@ -1720,7 +1724,8 @@ PyDoc_STRVAR(_functools_doc,
17201724"Tools that operate on functions." );
17211725
17221726static  PyMethodDef  _functools_methods [] =  {
1723-     {"reduce" ,          functools_reduce ,     METH_VARARGS , functools_reduce_doc },
1727+     {"reduce" , functools_reduce , METH_VARARGS |METH_KEYWORDS ,
1728+         functools_reduce_doc },
17241729    _FUNCTOOLS_CMP_TO_KEY_METHODDEF 
17251730    {NULL ,              NULL }           /* sentinel */ 
17261731};
0 commit comments