[Python-ideas] Map and filter should also convert StopIteration to RuntimeError
rosuav at gmail.com
Sun Dec 14 20:29:33 CET 2014
On Sun, Dec 14, 2014 at 11:47 PM, Devin Jeanpierre
<jeanpierreda at gmail.com> wrote:
> I worded myself poorly. It's not fine, it probably signals a bug in
> the callback (which is what makes #1 a reasonable option). What I mean
> is that callbacks can return any return value and raise any exception.
> Doing so shouldn't cause you to break the documented API of your type,
> including breaking its conformance to the iterator protocol. Anyway, I
> think we're on the same page, since I agree that your suggestions are
> justifiable, and you seem to agree that the status quo is not.
Sure. Then yes, I think we are broadly in agreement.
> This is not a "consenting adults"-type issue. map() and filter() don't
> correctly handle a perfectly plausible case, and as a result they
> violate their documented API. That is a bug. I'd rather fix the code
> than fix the docs. I can write a patch implementing Chris's #1, if it
> would be accepted. I don't think it needs a PEP.
Sounds fine to me, although without concrete use-cases I can't say it
would be a huge practical improvement. It's still a nice theoretical
improvement, tightening up a promise.
More information about the Python-ideas