[Python-ideas] Revert "RuntimeError: generator raised StopIteration"

Danilo J. S. Bellini danilo.bellini at gmail.com
Mon Sep 17 14:06:31 EDT 2018


Hi,

The idea is simple: restore the "next" built-in and the "StopIteration"
propagation behavior from Python 3.6.

I'm using Python 3.7 for a while (as it's the default in Arch Linux), and
there's one single backwards incompatible change from Python 3.6 that is
breaking the code of some packages from PyPI. The reason is always the
same: a "next" called inside a generator function was expected to propagate
the StopIteration, but that no longer happens.

As an example of something that had been made public (in PyPI), I've tried
to run:

from articlemeta.client import RestfulClient
journals = list(RestfulClient().journals(collection="ecu"))

This breaks with "RuntimeError: generator raised StopIteration". I already
warned the maintainers of that project, it probably will be fixed.

Another example (disclaimer: this time it's a package I've created): a
simple "pip install dose" only works on Python<3.7, since some
reStructuredText processing functions rely on the StopIteration propagation
from calls to "next". I needed this package last saturday for a Coding
Dojo, but I had to download the package from the repository and change some
stuff before starting the Dojo (during the time reserved for it).

I can fix this in the packages I'm maintaining by creating a new
"fix_python37_next_runtime_error" decorator to restore the old behavior on
every generator function that uses "next" in its body. But I can't do that
to all packages from other people, and having to change/monkeypatch
imported stuff in order to keep it working in this new Python version is
getting annoying already.

Perhaps adding a new kwarg to the "next" built-in to choose between a
"propagate" default or a "error" alternative would avoid this.

-- 
Danilo J. S. Bellini
---------------
"*It is not our business to set up prohibitions, but to arrive at
conventions.*" (R. Carnap)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180917/e15c5ddc/attachment.html>


More information about the Python-ideas mailing list