[issue33130] functools.reduce signature/docstring discordance

New submission from Vince Reuter <vince.reuter@gmail.com>: The signature for functools.reduce correctly refers to the collection parameter as an iterable, but the docstring refers to it as "sequence," which the input need not be and does not match the parameter name despite being italicized. ---------- assignee: docs@python components: Documentation messages: 314344 nosy: docs@python, vreuter priority: normal pull_requests: 5951 severity: normal status: open title: functools.reduce signature/docstring discordance type: enhancement versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33130> _______________________________________

Change by Serhiy Storchaka <storchaka+cpython@gmail.com>: ---------- nosy: +ncoghlan, rhettinger versions: -Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33130> _______________________________________

Terry J. Reedy <tjreedy@udel.edu> added the comment: inspect.signature(functools.reduce) raises, so I presume you mean the header for the reduce entry at https://docs.python.org/3/library/functools.html#functools.reduce. The first line of the docstring, functools.reduce.__doc__, also displayed by help(functools.reduce) has an old version of the signature, which disagrees also on the 3rd parameter name. doc header: functools.reduce(function, iterable[, initializer]) .__doc__: reduce(function, sequence[, initial]) -> value The current PR only touches the body of the doc entry, not what we call the docstring. It replaces 'sequence' with 'iterable'. Functools does not have a Python-coded backup for the C-coded reduce, which only accepts arguments by position. I have not looked at the C code, whose names are not accessible from Python. The doc and docstring should match, and should use the parameter names we would want to use of args were ever passed by name. So I think the docstring (in the C code) should be changed to match the doc. There should really be a '/,' to indicate that args must be passed by position, or do we only use that in ArgClinic signatures (which show up in help output)? ---------- nosy: +terry.reedy _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33130> _______________________________________

Nick Coghlan <ncoghlan@gmail.com> added the comment: +1 for switching over to `iterable` in the reduce docstring. As a possible enhancement for 3.8+ only, it would be reasonable to start converting functools over to Argument Clinic in order to improve the introspection support. (Note that only some APIs could be converted though, as others have more complex signatures that AC doesn't yet support: https://bugs.python.org/issue20291) ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33130> _______________________________________

Ben Finney <ben+python@benfinney.id.au> added the comment: The library documentation (e.g. file:///usr/share/doc/python3/html/library/functools.html#functools.reduce ) also has this dissonance:
functools.reduce(`function`, `iterable` [, `initializer` ])
Apply function of two arguments cumulatively to the items of `sequence`, from left to right, so as to reduce the sequence to a single value.
---------- nosy: +bignose title: functools.reduce signature/docstring discordance -> functools.reduce signature uses `iterable`, documentation should use the same term _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33130> _______________________________________

Ben Finney <ben+python@benfinney.id.au> added the comment: Hah, sorry to use a local-filesystem URL. (Hooray for locally-installed developer documentation!) The same section is online at https://docs.python.org/3/library/functools.html#functools.reduce . ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33130> _______________________________________

Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment: The original report for documentation seems to have been fixed with https://github.com/python/cpython/pull/9634 and the linked PR is closed with no changes to be merged. So I would propose closing if this was only with respect to changing documentation and not docstring. As an additional note issue32321 added a python fallback implementation of functools.reduce that uses the same docstring like the C implementation. Thanks @vreuter for the report. ---------- nosy: +xtreak _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33130> _______________________________________
participants (6)
-
Ben Finney
-
Karthikeyan Singaravelan
-
Nick Coghlan
-
Serhiy Storchaka
-
Terry J. Reedy
-
Vince Reuter