From b5ac476b8957927ad96bd4890b43dab03dafd6fb Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Thu, 24 Oct 2024 13:48:45 +0530 Subject: [PATCH 01/14] gh-125916: convert reduce() to Argument Clinic --- Modules/_functoolsmodule.c | 46 +++++++++++++++++----------- Modules/clinic/_functoolsmodule.c.h | 47 ++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 18 deletions(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 802b1cf792c555..9c97dc03c4506d 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -932,15 +932,31 @@ _functools_cmp_to_key_impl(PyObject *module, PyObject *mycmp) /* reduce (used to be a builtin) ********************************************/ -// Not converted to argument clinic, because of `args` in-place modification. -// AC will affect performance. +/*[clinic input] +_functools.reduce + + function as func: object + iterable as seq: object + initial as result: object(c_default="NULL") = _functools._initial_missing + / + +Apply a function of two arguments cumulatively to an iterable, from left to right. + +This efficiently reduces the iterable to a single value. If initial is present, +it is placed before the items of the iterable in the calculation, and serves as +a default when the iterable is empty. + +For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) +calculates ((((1 + 2) + 3) + 4) + 5). +[clinic start generated code]*/ + static PyObject * -functools_reduce(PyObject *self, PyObject *args) +_functools_reduce_impl(PyObject *module, PyObject *func, PyObject *seq, + PyObject *result) +/*[clinic end generated code: output=30d898fe1267c79d input=0315d8e82beb5e6d]*/ { - PyObject *seq, *func, *result = NULL, *it; + PyObject *args, *it; - if (!PyArg_UnpackTuple(args, "reduce", 2, 3, &func, &seq, &result)) - return NULL; if (result != NULL) Py_INCREF(result); @@ -1006,16 +1022,6 @@ functools_reduce(PyObject *self, PyObject *args) return NULL; } -PyDoc_STRVAR(functools_reduce_doc, -"reduce(function, iterable[, initial], /) -> value\n\ -\n\ -Apply a function of two arguments cumulatively to the items of a sequence\n\ -or iterable, from left to right, so as to reduce the iterable to a single\n\ -value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\ -((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\ -of the iterable in the calculation, and serves as a default when the\n\ -iterable is empty."); - /* lru_cache object **********************************************************/ /* There are four principal algorithmic differences from the pure python version: @@ -1720,7 +1726,7 @@ PyDoc_STRVAR(_functools_doc, "Tools that operate on functions."); static PyMethodDef _functools_methods[] = { - {"reduce", functools_reduce, METH_VARARGS, functools_reduce_doc}, + _FUNCTOOLS_REDUCE_METHODDEF _FUNCTOOLS_CMP_TO_KEY_METHODDEF {NULL, NULL} /* sentinel */ }; @@ -1789,6 +1795,12 @@ _functools_exec(PyObject *module) // lru_list_elem is used only in _lru_cache_wrapper. // So we don't expose it in module namespace. + if (PyModule_Add(module, "_initial_missing", + PyObject_New(PyObject, &PyBaseObject_Type)) < 0) + { + return -1; + } + return 0; } diff --git a/Modules/clinic/_functoolsmodule.c.h b/Modules/clinic/_functoolsmodule.c.h index e98984dc4d3a09..92f9e522ef4da2 100644 --- a/Modules/clinic/_functoolsmodule.c.h +++ b/Modules/clinic/_functoolsmodule.c.h @@ -67,6 +67,51 @@ _functools_cmp_to_key(PyObject *module, PyObject *const *args, Py_ssize_t nargs, return return_value; } +PyDoc_STRVAR(_functools_reduce__doc__, +"reduce($module, function, iterable,\n" +" initial=_functools._initial_missing, /)\n" +"--\n" +"\n" +"Apply a function of two arguments cumulatively to an iterable, from left to right.\n" +"\n" +"This efficiently reduces the iterable to a single value. If initial is present,\n" +"it is placed before the items of the iterable in the calculation, and serves as\n" +"a default when the iterable is empty.\n" +"\n" +"For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n" +"calculates ((((1 + 2) + 3) + 4) + 5)."); + +#define _FUNCTOOLS_REDUCE_METHODDEF \ + {"reduce", _PyCFunction_CAST(_functools_reduce), METH_FASTCALL, _functools_reduce__doc__}, + +static PyObject * +_functools_reduce_impl(PyObject *module, PyObject *func, PyObject *seq, + PyObject *result); + +static PyObject * +_functools_reduce(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *func; + PyObject *seq; + PyObject *result = NULL; + + if (!_PyArg_CheckPositional("reduce", nargs, 2, 3)) { + goto exit; + } + func = args[0]; + seq = args[1]; + if (nargs < 3) { + goto skip_optional; + } + result = args[2]; +skip_optional: + return_value = _functools_reduce_impl(module, func, seq, result); + +exit: + return return_value; +} + PyDoc_STRVAR(_functools__lru_cache_wrapper_cache_info__doc__, "cache_info($self, /)\n" "--\n" @@ -114,4 +159,4 @@ _functools__lru_cache_wrapper_cache_clear(PyObject *self, PyObject *Py_UNUSED(ig return return_value; } -/*[clinic end generated code: output=755265bb6d5ea751 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2721ebc446e68d0f input=a9049054013a1b77]*/ From 0a0c71ca7f6b4f01e3994512a7de7a5f732644f0 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sat, 26 Oct 2024 06:11:41 +0300 Subject: [PATCH 02/14] +1 --- Lib/test/test_inspect/test_inspect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 77fdc6f238437e..8614f28a113f50 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -5695,8 +5695,8 @@ def test_faulthandler_module_has_signatures(self): self._test_module_has_signatures(faulthandler, unsupported_signature=unsupported_signature) def test_functools_module_has_signatures(self): - no_signature = {'reduce'} - self._test_module_has_signatures(functools, no_signature) + unsupported_signature = {"reduce"} + self._test_module_has_signatures(functools, unsupported_signature=unsupported_signature) def test_gc_module_has_signatures(self): import gc From 5477d572bf0d299c8d3c897226f4a0fc89720776 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 27 Oct 2024 04:52:59 +0300 Subject: [PATCH 03/14] address review: make signature unrepresentable again --- Lib/test/test_inspect/test_inspect.py | 4 ++-- Modules/_functoolsmodule.c | 11 +++-------- Modules/clinic/_functoolsmodule.c.h | 5 ++--- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 8614f28a113f50..77fdc6f238437e 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -5695,8 +5695,8 @@ def test_faulthandler_module_has_signatures(self): self._test_module_has_signatures(faulthandler, unsupported_signature=unsupported_signature) def test_functools_module_has_signatures(self): - unsupported_signature = {"reduce"} - self._test_module_has_signatures(functools, unsupported_signature=unsupported_signature) + no_signature = {'reduce'} + self._test_module_has_signatures(functools, no_signature) def test_gc_module_has_signatures(self): import gc diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 9c97dc03c4506d..70b27a077cd592 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -933,11 +933,12 @@ _functools_cmp_to_key_impl(PyObject *module, PyObject *mycmp) /* reduce (used to be a builtin) ********************************************/ /*[clinic input] +@text_signature "($module, function, iterable[, initial], /)" _functools.reduce function as func: object iterable as seq: object - initial as result: object(c_default="NULL") = _functools._initial_missing + initial as result: object = NULL / Apply a function of two arguments cumulatively to an iterable, from left to right. @@ -953,7 +954,7 @@ calculates ((((1 + 2) + 3) + 4) + 5). static PyObject * _functools_reduce_impl(PyObject *module, PyObject *func, PyObject *seq, PyObject *result) -/*[clinic end generated code: output=30d898fe1267c79d input=0315d8e82beb5e6d]*/ +/*[clinic end generated code: output=30d898fe1267c79d input=d85ca22bf7ee578b]*/ { PyObject *args, *it; @@ -1795,12 +1796,6 @@ _functools_exec(PyObject *module) // lru_list_elem is used only in _lru_cache_wrapper. // So we don't expose it in module namespace. - if (PyModule_Add(module, "_initial_missing", - PyObject_New(PyObject, &PyBaseObject_Type)) < 0) - { - return -1; - } - return 0; } diff --git a/Modules/clinic/_functoolsmodule.c.h b/Modules/clinic/_functoolsmodule.c.h index 92f9e522ef4da2..f4987e81a3d627 100644 --- a/Modules/clinic/_functoolsmodule.c.h +++ b/Modules/clinic/_functoolsmodule.c.h @@ -68,8 +68,7 @@ _functools_cmp_to_key(PyObject *module, PyObject *const *args, Py_ssize_t nargs, } PyDoc_STRVAR(_functools_reduce__doc__, -"reduce($module, function, iterable,\n" -" initial=_functools._initial_missing, /)\n" +"reduce($module, function, iterable[, initial], /)\n" "--\n" "\n" "Apply a function of two arguments cumulatively to an iterable, from left to right.\n" @@ -159,4 +158,4 @@ _functools__lru_cache_wrapper_cache_clear(PyObject *self, PyObject *Py_UNUSED(ig return return_value; } -/*[clinic end generated code: output=2721ebc446e68d0f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8be939adb106de8f input=a9049054013a1b77]*/ From 42225f9c5527fbcf3a339bcb5e9780c781615cf2 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 27 Oct 2024 05:10:05 +0300 Subject: [PATCH 04/14] +1 --- Lib/test/test_inspect/test_inspect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 77fdc6f238437e..8614f28a113f50 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -5695,8 +5695,8 @@ def test_faulthandler_module_has_signatures(self): self._test_module_has_signatures(faulthandler, unsupported_signature=unsupported_signature) def test_functools_module_has_signatures(self): - no_signature = {'reduce'} - self._test_module_has_signatures(functools, no_signature) + unsupported_signature = {"reduce"} + self._test_module_has_signatures(functools, unsupported_signature=unsupported_signature) def test_gc_module_has_signatures(self): import gc From a22cef96baa8734eb5879cf532fb9e1df253c704 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 27 Oct 2024 18:24:52 +0300 Subject: [PATCH 05/14] Improve functools.reduce() docstring PEP 257 says that "Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description." This is also a requirement from the Argument Clinic. --- Lib/functools.py | 14 ++++++++------ Modules/_functoolsmodule.c | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Lib/functools.py b/Lib/functools.py index 9d53d3601559b2..1917a3b688cedd 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -238,12 +238,14 @@ def reduce(function, sequence, initial=_initial_missing): """ reduce(function, iterable[, initial], /) -> value - Apply a function of two arguments cumulatively to the items of a sequence - or iterable, from left to right, so as to reduce the iterable to a single - value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates - ((((1+2)+3)+4)+5). If initial is present, it is placed before the items - of the iterable in the calculation, and serves as a default when the - iterable is empty. + Apply a function of two arguments cumulatively to an iterable, from left to right. + + This efficiently reduces the iterable to a single value. If initial is present, + it is placed before the items of the iterable in the calculation, and serves as + a default when the iterable is empty. + + For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) + calculates ((((1 + 2) + 3) + 4) + 5). """ it = iter(sequence) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 802b1cf792c555..a57246be99151e 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -1009,12 +1009,14 @@ functools_reduce(PyObject *self, PyObject *args) PyDoc_STRVAR(functools_reduce_doc, "reduce(function, iterable[, initial], /) -> value\n\ \n\ -Apply a function of two arguments cumulatively to the items of a sequence\n\ -or iterable, from left to right, so as to reduce the iterable to a single\n\ -value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\ -((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\ -of the iterable in the calculation, and serves as a default when the\n\ -iterable is empty."); +Apply a function of two arguments cumulatively to an iterable, from left to right.\n\ +\n\ +This efficiently reduces the iterable to a single value. If initial is present,\n\ +it is placed before the items of the iterable in the calculation, and serves as\n\ +a default when the iterable is empty.\n\ +\n\ +For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n\ +calculates ((((1 + 2) + 3) + 4) + 5)."); /* lru_cache object **********************************************************/ From ea5ae96662f8cb32b996c96bed5c0ba8f67726af Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 28 Oct 2024 07:26:15 +0300 Subject: [PATCH 06/14] Apply suggestions from code review Co-authored-by: Erlend E. Aasland --- Lib/functools.py | 2 +- Modules/_functoolsmodule.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/functools.py b/Lib/functools.py index 1917a3b688cedd..b64e931c6bdd20 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -240,7 +240,7 @@ def reduce(function, sequence, initial=_initial_missing): Apply a function of two arguments cumulatively to an iterable, from left to right. - This efficiently reduces the iterable to a single value. If initial is present, + This effectively reduces the iterable to a single value. If initial is present, it is placed before the items of the iterable in the calculation, and serves as a default when the iterable is empty. diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index a57246be99151e..da87f7304553c9 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -1011,7 +1011,7 @@ PyDoc_STRVAR(functools_reduce_doc, \n\ Apply a function of two arguments cumulatively to an iterable, from left to right.\n\ \n\ -This efficiently reduces the iterable to a single value. If initial is present,\n\ +This effectively reduces the iterable to a single value. If initial is present,\n\ it is placed before the items of the iterable in the calculation, and serves as\n\ a default when the iterable is empty.\n\ \n\ From 6b268a6e90f25a4b2a62f22561e4506215eb3234 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 28 Oct 2024 07:37:49 +0300 Subject: [PATCH 07/14] Update Modules/_functoolsmodule.c --- Modules/_functoolsmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 70b27a077cd592..db725e79d05038 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -943,7 +943,7 @@ _functools.reduce Apply a function of two arguments cumulatively to an iterable, from left to right. -This efficiently reduces the iterable to a single value. If initial is present, +This effectively reduces the iterable to a single value. If initial is present, it is placed before the items of the iterable in the calculation, and serves as a default when the iterable is empty. From fed491178a9917b73242560a6a2e13eb3068b283 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 29 Oct 2024 04:33:45 +0300 Subject: [PATCH 08/14] Update Lib/functools.py Co-authored-by: Erlend E. Aasland --- Lib/functools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/functools.py b/Lib/functools.py index b64e931c6bdd20..27abd622a8cff1 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -238,7 +238,7 @@ def reduce(function, sequence, initial=_initial_missing): """ reduce(function, iterable[, initial], /) -> value - Apply a function of two arguments cumulatively to an iterable, from left to right. + Apply a function of two arguments cumulatively to the items of an iterable, from left to right. This effectively reduces the iterable to a single value. If initial is present, it is placed before the items of the iterable in the calculation, and serves as From e0e467c84a65313bc18a4b10c70f5c1277f3e903 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 29 Oct 2024 08:42:54 +0100 Subject: [PATCH 09/14] Update Modules/_functoolsmodule.c --- Modules/_functoolsmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index da87f7304553c9..da4e088e54621e 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -1009,7 +1009,7 @@ functools_reduce(PyObject *self, PyObject *args) PyDoc_STRVAR(functools_reduce_doc, "reduce(function, iterable[, initial], /) -> value\n\ \n\ -Apply a function of two arguments cumulatively to an iterable, from left to right.\n\ +Apply a function of two arguments cumulatively to the items of an iterable, from left to right.\n\ \n\ This effectively reduces the iterable to a single value. If initial is present,\n\ it is placed before the items of the iterable in the calculation, and serves as\n\ From 94fc86dc62bd1ea622b37443d19f98417b7f74ed Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 29 Oct 2024 11:17:10 +0300 Subject: [PATCH 10/14] + clinic --- Modules/_functoolsmodule.c | 2 +- Modules/clinic/_functoolsmodule.c.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 260991fcf70973..bceacc36b7cfb1 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -954,7 +954,7 @@ calculates ((((1 + 2) + 3) + 4) + 5).") static PyObject * _functools_reduce_impl(PyObject *module, PyObject *func, PyObject *seq, PyObject *result) -/*[clinic end generated code: output=30d898fe1267c79d input=d85ca22bf7ee578b]*/ +/*[clinic end generated code: output=30d898fe1267c79d input=a01a4f88eb058f3b]*/ { PyObject *args, *it; diff --git a/Modules/clinic/_functoolsmodule.c.h b/Modules/clinic/_functoolsmodule.c.h index f4987e81a3d627..916d939d1fa797 100644 --- a/Modules/clinic/_functoolsmodule.c.h +++ b/Modules/clinic/_functoolsmodule.c.h @@ -71,14 +71,14 @@ PyDoc_STRVAR(_functools_reduce__doc__, "reduce($module, function, iterable[, initial], /)\n" "--\n" "\n" -"Apply a function of two arguments cumulatively to an iterable, from left to right.\n" +"Apply a function of two arguments cumulatively to the items of an iterable, from left to right.\n" "\n" -"This efficiently reduces the iterable to a single value. If initial is present,\n" +"This effectively reduces the iterable to a single value. If initial is present,\n" "it is placed before the items of the iterable in the calculation, and serves as\n" "a default when the iterable is empty.\n" "\n" "For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n" -"calculates ((((1 + 2) + 3) + 4) + 5)."); +"calculates ((((1 + 2) + 3) + 4) + 5).\")"); #define _FUNCTOOLS_REDUCE_METHODDEF \ {"reduce", _PyCFunction_CAST(_functools_reduce), METH_FASTCALL, _functools_reduce__doc__}, @@ -158,4 +158,4 @@ _functools__lru_cache_wrapper_cache_clear(PyObject *self, PyObject *Py_UNUSED(ig return return_value; } -/*[clinic end generated code: output=8be939adb106de8f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=866d9921a492239f input=a9049054013a1b77]*/ From d86570b5c2ecfbb05b2658a39f239222a9f36197 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 29 Oct 2024 13:55:58 +0300 Subject: [PATCH 11/14] Update Modules/_functoolsmodule.c Co-authored-by: Jelle Zijlstra --- Modules/_functoolsmodule.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index bceacc36b7cfb1..125b41c33a536c 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -933,7 +933,6 @@ _functools_cmp_to_key_impl(PyObject *module, PyObject *mycmp) /* reduce (used to be a builtin) ********************************************/ /*[clinic input] -@text_signature "($module, function, iterable[, initial], /)" _functools.reduce function as func: object From b011243a3b5efbd45364a97add8783730f94f041 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 29 Oct 2024 13:58:03 +0300 Subject: [PATCH 12/14] +1 --- Modules/_functoolsmodule.c | 2 +- Modules/clinic/_functoolsmodule.c.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 125b41c33a536c..95b757db0ffb8a 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -953,7 +953,7 @@ calculates ((((1 + 2) + 3) + 4) + 5).") static PyObject * _functools_reduce_impl(PyObject *module, PyObject *func, PyObject *seq, PyObject *result) -/*[clinic end generated code: output=30d898fe1267c79d input=a01a4f88eb058f3b]*/ +/*[clinic end generated code: output=30d898fe1267c79d input=cadc408bded707d1]*/ { PyObject *args, *it; diff --git a/Modules/clinic/_functoolsmodule.c.h b/Modules/clinic/_functoolsmodule.c.h index 916d939d1fa797..1800f33ac3a91a 100644 --- a/Modules/clinic/_functoolsmodule.c.h +++ b/Modules/clinic/_functoolsmodule.c.h @@ -68,7 +68,7 @@ _functools_cmp_to_key(PyObject *module, PyObject *const *args, Py_ssize_t nargs, } PyDoc_STRVAR(_functools_reduce__doc__, -"reduce($module, function, iterable[, initial], /)\n" +"reduce($module, function, iterable, initial=, /)\n" "--\n" "\n" "Apply a function of two arguments cumulatively to the items of an iterable, from left to right.\n" @@ -158,4 +158,4 @@ _functools__lru_cache_wrapper_cache_clear(PyObject *self, PyObject *Py_UNUSED(ig return return_value; } -/*[clinic end generated code: output=866d9921a492239f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9cf40255d4e89c27 input=a9049054013a1b77]*/ From ebed8da4ccf9d8f71a99aea2186f8655220cdf16 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 1 Nov 2024 18:19:10 +0300 Subject: [PATCH 13/14] Update Modules/_functoolsmodule.c Co-authored-by: Serhiy Storchaka --- Modules/_functoolsmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 95b757db0ffb8a..2fbd0e8cdb9694 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -947,7 +947,7 @@ it is placed before the items of the iterable in the calculation, and serves as a default when the iterable is empty. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) -calculates ((((1 + 2) + 3) + 4) + 5).") +calculates ((((1 + 2) + 3) + 4) + 5). [clinic start generated code]*/ static PyObject * From 57f71d0cbb07bdda8d4c3b22289b5c8625bf1b30 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 1 Nov 2024 18:34:15 +0300 Subject: [PATCH 14/14] +1 --- Modules/_functoolsmodule.c | 2 +- Modules/clinic/_functoolsmodule.c.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 2fbd0e8cdb9694..d2afe1a1bea018 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -953,7 +953,7 @@ calculates ((((1 + 2) + 3) + 4) + 5). static PyObject * _functools_reduce_impl(PyObject *module, PyObject *func, PyObject *seq, PyObject *result) -/*[clinic end generated code: output=30d898fe1267c79d input=cadc408bded707d1]*/ +/*[clinic end generated code: output=30d898fe1267c79d input=d233c2670cba7f66]*/ { PyObject *args, *it; diff --git a/Modules/clinic/_functoolsmodule.c.h b/Modules/clinic/_functoolsmodule.c.h index 1800f33ac3a91a..0564921034be47 100644 --- a/Modules/clinic/_functoolsmodule.c.h +++ b/Modules/clinic/_functoolsmodule.c.h @@ -78,7 +78,7 @@ PyDoc_STRVAR(_functools_reduce__doc__, "a default when the iterable is empty.\n" "\n" "For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n" -"calculates ((((1 + 2) + 3) + 4) + 5).\")"); +"calculates ((((1 + 2) + 3) + 4) + 5)."); #define _FUNCTOOLS_REDUCE_METHODDEF \ {"reduce", _PyCFunction_CAST(_functools_reduce), METH_FASTCALL, _functools_reduce__doc__}, @@ -158,4 +158,4 @@ _functools__lru_cache_wrapper_cache_clear(PyObject *self, PyObject *Py_UNUSED(ig return return_value; } -/*[clinic end generated code: output=9cf40255d4e89c27 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=214d6c6307cfcd91 input=a9049054013a1b77]*/