This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Naris R, serhiy.storchaka
Date 2018-04-21.15:19:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1524323948.34.0.682650639539.issue33323@psf.upfronthosting.co.za>
In-reply-to
Content
In Python 2.7 and 3.6 I got the following traceback for the second case:

Traceback (most recent call last):
  File "issue33323.py", line 21, in <module>
    min(bad(i) for i in range(7)) # unhelpful error message
ValueError: max() arg is an empty sequence

StopIteration in generator expressions didn't treated as an error. It just stopped the iteration. The exception is raised by the consumer of generated values, min(), because it doesn't work with empty sequences by default.

This behavior caused hard to investigate bugs and was considered harmful. Fortunately it will be fixed in Python 3.7. The traceback in 3.7:

Traceback (most recent call last):
  File "issue33323.py", line 21, in <genexpr>
    min(bad(i) for i in range(7)) # unhelpful error message
  File "issue33323.py", line 11, in bad
    return n - bad_exception()
  File "issue33323.py", line 5, in bad_exception
    return next(iter([]))
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "issue33323.py", line 21, in <module>
    min(bad(i) for i in range(7)) # unhelpful error message
RuntimeError: generator raised StopIteration

You can enable this behavior in earlier versions (3.5+) by adding the future import:

from __future__ import generator_stop

See PEP 479 for details.
History
Date User Action Args
2018-04-21 15:19:08serhiy.storchakasetrecipients: + serhiy.storchaka, Naris R
2018-04-21 15:19:08serhiy.storchakasetmessageid: <1524323948.34.0.682650639539.issue33323@psf.upfronthosting.co.za>
2018-04-21 15:19:08serhiy.storchakalinkissue33323 messages
2018-04-21 15:19:08serhiy.storchakacreate