Message315571
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. |
|
Date |
User |
Action |
Args |
2018-04-21 15:19:08 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, Naris R |
2018-04-21 15:19:08 | serhiy.storchaka | set | messageid: <1524323948.34.0.682650639539.issue33323@psf.upfronthosting.co.za> |
2018-04-21 15:19:08 | serhiy.storchaka | link | issue33323 messages |
2018-04-21 15:19:08 | serhiy.storchaka | create | |
|