@@ -938,21 +938,22 @@ _functools.reduce
938938 function as func: object
939939 iterable as seq: object
940940 /
941- initial as result: object(c_default="NULL") = None
941+ initial as result: object(c_default="NULL") = _functools._initial_missing
942942
943- Apply a function of two arguments cumulatively.
943+ Apply a function of two arguments cumulatively to an iterable, from left to right .
944944
945- Apply it to the items of a sequence or iterable, from left to right, so as to
946- reduce the iterable to a single value. For example, reduce(lambda x, y: x+y,
947- [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). If initial is present, it is
948- placed before the items of the iterable in the calculation, and serves as a
949- default when the iterable is empty.
945+ This efficiently reduces the iterable to a single value. If initial is present,
946+ it is placed before the items of the iterable in the calculation, and serves as
947+ a default when the iterable is empty.
948+
949+ For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
950+ calculates ((((1+2)+3)+4)+5).
950951[clinic start generated code]*/
951952
952953static PyObject *
953954_functools_reduce_impl (PyObject * module , PyObject * func , PyObject * seq ,
954955 PyObject * result )
955- /*[clinic end generated code: output=30d898fe1267c79d input=b7082b8b1473fdc2 ]*/
956+ /*[clinic end generated code: output=30d898fe1267c79d input=40be8069bcbc1a75 ]*/
956957{
957958 PyObject * args , * it ;
958959
@@ -1794,6 +1795,10 @@ _functools_exec(PyObject *module)
17941795 // lru_list_elem is used only in _lru_cache_wrapper.
17951796 // So we don't expose it in module namespace.
17961797
1798+ if (PyModule_Add (module , "_initial_missing" , _PyObject_New (& PyBaseObject_Type )) < 0 ) {
1799+ return -1 ;
1800+ }
1801+
17971802 return 0 ;
17981803}
17991804
0 commit comments