[issue31082] reduce takes iterable, not just sequence
New submission from Stefan Pochmann:
functools.reduce has a parameter called "iterable" and it only needs to be an iterable, not a sequence.
The paragraph documenting it says "sequence" instead of "iterable" six times:
https://docs.python.org/3/library/functools.html#functools.reduce
The help shown by executing "help(functools.reduce)" in Python additionally actually names the parameter "sequence" in the signature.
----------
assignee: docs@python
components: Documentation
messages: 299520
nosy: Stefan Pochmann, docs@python
priority: normal
severity: normal
status: open
title: reduce takes iterable, not just sequence
type: enhancement
versions: Python 3.6, Python 3.7
_______________________________________
Python tracker
Terry J. Reedy added the comment:
Serhiy, given that the parameters of reduce are currently positional only (by experiment, it has not gotten the C.A. treatment yet), can 'sequence' in the signature in the docstring be changes to 'iterable'?
----------
nosy: +serhiy.storchaka, terry.reedy
_______________________________________
Python tracker
Serhiy Storchaka added the comment:
Yes, I think it can. But be aware that "sequence" is used not only in the signature, but in following description.
The term "sequence" in the documentation and the docstring looks to me like a synonym of "iterable", not a reference to collections.abc.Sequence. I don't know how the wording can be improved. Maybe looking at the documentation of builtins filter, map, zip, and itertools functions can help.
----------
nosy: +ncoghlan, rhettinger
_______________________________________
Python tracker
Nick Coghlan added the comment:
Checking older versions of the docs, it looks like we simply haven't reworded those docs since Python 2.0 (when the "list" of the 1.5 docs became "sequence" for 2.0).
So I think the most appropriate resolution here would be to replace the current use of "sequence" with "iterable" in both the code and the documentation.
----------
_______________________________________
Python tracker
Serhiy Storchaka added the comment:
The term "sequence" also is used in the docstring of itertools.starmap() (actually an iterable is accepted).
----------
_______________________________________
Python tracker
Change by Zackery Spytz
Dong-hee Na
Change by Dong-hee Na
participants (6)
-
Dong-hee Na
-
Nick Coghlan
-
Serhiy Storchaka
-
Stefan Pochmann
-
Terry J. Reedy
-
Zackery Spytz