On Tue, Apr 21, 2020 at 11:36 AM Serhiy Storchaka <storch...@gmail.com>
wrote:

> 20.04.20 23:33, Andrew Barnert via Python-ideas пише:
> > Should this print 1 or 2 or raise StopIteration or be a don’t-care?
> >
> > Should it matter if you zip(y, x, strict=True) instead?
>
> It should print 2 in both cases. The only way to determine whether the
> iterator ends is to try to get its next value. And this value (1) will
> lost, because there is no way to return it or "unput" to the iterator.
> There is no reason to consume more values, so StopIteration is irrelevant.
>
> There is more interesting example:
>
>      x = iter(range(5))
>      y = [0]
>      z = iter(range(5))
>      try:
>          zipped = list(zip(x, y, z, strict=True))
>      except ValueError: # assuming that’s the exception you want?
>         assert zipped == [(0, 0, 0)]
>         assert next(x) == 2
>          print(next(z))
>
> Should this print 1 or 2?
>
> The simple implementation using zip_longest() would print 2, but more
> optimal implementation can print 1.
>

Your first assert is wrong.

I think it should print 1 (i.e. raise the exception immediately when the
first iterator is too short) but I don't feel too strongly about this, so
if people are pushing towards 2, I'm okay with that.

If there's agreement to move forward on this suggestion, here's what I
volunteer to do:

  1. Write tests.
  2. Write documentation.

I'm gonna need someone else to write the implementation.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7PX4R23BPSQSFSQYQIKWWU7CY7JV7J3M/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to