]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-149083: use sentinel to fix _functools.reduce() signature (GH-149591) ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 10 May 2026 23:32:35 +0000 (01:32 +0200)
committerGitHub <noreply@github.com>
Sun, 10 May 2026 23:32:35 +0000 (23:32 +0000)
gh-149083: use sentinel to fix _functools.reduce() signature (GH-149591)
(cherry picked from commit c6fd7de64ac7591a9708c14a34737eb9baf050bc)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Lib/inspect.py
Lib/test/test_inspect/test_inspect.py
Modules/_functoolsmodule.c
Modules/clinic/_functoolsmodule.c.h

index a96b3dc954ef0ca850b17ca158ea79255460cfc5..dc5a6e3be883bb061607b28fe17f9f543c2c0e0b 100644 (file)
@@ -2200,7 +2200,8 @@ def _signature_fromstr(cls, obj, s, skip_bound_arg=True):
             except NameError:
                 raise ValueError
 
-        if isinstance(value, (str, int, float, bytes, bool, type(None))):
+        if isinstance(value, (str, int, float, bytes, bool, type(None),
+                              sentinel)):
             return ast.Constant(value)
         raise ValueError
 
index 9028d42c617fb4baa6b525d7b8da603c1e05eed9..7351f97fd9a4b5c8889c8299eab671749309ce06 100644 (file)
@@ -6255,8 +6255,7 @@ class TestSignatureDefinitions(unittest.TestCase):
         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)
+        self._test_module_has_signatures(functools)
 
     def test_gc_module_has_signatures(self):
         import gc
index 19bdf3d47c2fad5ca1c1ef6c616b2a4ff4bf1302..c702eecc700ac80c34f492b952d3f94f716b418d 100644 (file)
@@ -1066,7 +1066,7 @@ _functools.reduce
     function as func: object
     iterable as seq: object
     /
-    initial as result: object = NULL
+    initial as result: object(c_default="NULL") = functools._initial_missing
 
 Apply a function of two arguments cumulatively to the items of an iterable, from left to right.
 
@@ -1081,7 +1081,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=4ccfb74548ce5170]*/
+/*[clinic end generated code: output=30d898fe1267c79d input=5c9088c98ffe2793]*/
 {
     PyObject *args, *it;
 
index 23f6663108503122f2657ca4bc68616226fe0863..87cdef2ad3cff3bf5449ce6d98d9b6eb6e6f4a9e 100644 (file)
@@ -71,7 +71,8 @@ exit:
 }
 
 PyDoc_STRVAR(_functools_reduce__doc__,
-"reduce($module, function, iterable, /, initial=<unrepresentable>)\n"
+"reduce($module, function, iterable, /,\n"
+"       initial=functools._initial_missing)\n"
 "--\n"
 "\n"
 "Apply a function of two arguments cumulatively to the items of an iterable, from left to right.\n"
@@ -192,4 +193,4 @@ _functools__lru_cache_wrapper_cache_clear(PyObject *self, PyObject *Py_UNUSED(ig
 
     return return_value;
 }
-/*[clinic end generated code: output=7f2abc718fcc35d5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ac9e26d0a5a23d40 input=a9049054013a1b77]*/