Serhiy Storchaka <[email protected]> added the comment:
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.
----------
components: +Interpreter Core
resolution: -> out of date
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue33323>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com