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

Oscar Benjamin oscar.j.benjamin at gmail.com
Sat Dec 13 13:23:29 CET 2014


On 13 December 2014 at 06:10, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
>
> In contrast, the "fix" in this case would need to be applied to the *called* functions or their callees, possibly far removed from the map/filter/accumulate call.  If that function is in third-party code or in a C-library, then the mitigation would require redesigning the call logic completely (not fun) or to wrap the function in something transforms a StopIteration into a custom exception and then re-catches the custom exception upstream from the higher-order function (also not fun).

Is it a common pattern to raise StopIteration from some deeply nested
function (that isn't itself a __next__ method) in order to terminate
iteration at some far removed level? I think that PEP 479 largely
breaks that pattern if it is since it will no longer work if any
generators are involved.


Oscar


More information about the Python-ideas mailing list