
June 12, 2023
8:11 p.m.
On 12 Jun 2023, at 16:55, BoppreH via Python-ideas <python-ideas@python.org> wrote:
Then the empty list creates hard-to-track bugs. I'm familiar with the iterator protocol and why the behavior above happens, but couldn't it be prevented?
I don’t think so. It is not always a bug that an iterator is empty. For example this pattern: args = iter(sys.argv) progname = next(args) mandatory_arg = next(args) for arg in args: print(‘optional arg’, next(arg)) Your proposal will traceback for the for loop if there are no optional args. Barry