[Python-ideas] Map and filter should also convert StopIteration to RuntimeError

Ethan Furman ethan at stoneleaf.us
Sat Dec 13 07:46:16 CET 2014


On 12/12/2014 10:10 PM, Raymond Hettinger wrote:

> I'm -1 on this proposal.   
> 
> Generators are part of the language internals and language spec, so Guido
> can reasonably decide to take this in whatever direction he wants.   In
> contrast, now you're moving on to parts of the language library that merely
> call functions and return results.
> 
> It is not the responsibility of accumulate(), filter(), map(), or any other
> higher-order functions to impose rules about what those functions are allowed
> to do  [...]

Completely agreed.

While the problem (at least in some views, my own included) is really about how next() treats an empty iterable, the
biggest reason against changing how next() works is because of all the correctly written code that would be broken (by
"correct" I mean code that already guards against next() raising a StopIteration).

Conversely, the biggest reason for changing just generators (again, at least in my view ;) is that when writing a
generator it's easy to forget that you are actually mucking about with internals and should be guarding against an
unexpected flow control exception occuring, as it were, out of the blue.

--
~Ethan~

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141212/22d7b8c0/attachment.sig>


More information about the Python-ideas mailing list