[Python-ideas] __len__() for map()

Adam Johnson mail.yogi841 at gmail.com
Sat Dec 1 07:45:08 EST 2018


On Sat, 1 Dec 2018 at 10:44, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> It's not -- the StopIteration isn't terminating the map,
> it's terminating the iteration being performed by tuple().

That was a poor choice of wording on my part, it's rather that map
doesn't do anything special in that regard. To whatever is iterating
over the map, any unexpected StopIteration from the function isn't
distinguishable from the expected one from the iterable(s) being
exhausted.

This issue was dealt with in generators by PEP-479 (by replacing the
StopIteration with a RuntimeError). Whilst map, filter, and others may
not be generators, I would expect them to be consistent with that PEP
when handling the same issue.


More information about the Python-ideas mailing list