On 2020-04-21 11:20 a.m., Eric V. Smith wrote:
On 4/21/2020 10:14 AM, Eric V. Smith wrote:
On 4/21/2020 10:10 AM, Soni L. wrote:
I feel like zip could return partial results:

try:
  next(zip([0], []))
except StopIteration as exc:
  assert StopIteration.args == (0,)

how much would this break?

It would break a lot of code, and so it won't happen.
Actually, I'm not so sure of that, presuming you mean "exc.args", not "StopIteration.args". And since that's currently set to "()", at least in my tests, maybe setting it wouldn't break much code. But it's probably a non-zero amount.

... yeah I did not pay as much attention to that hypothetical code as I should have.


You can use itertools.zip_longest with your own sentinel to get the same behavior.

In your proposal, what would next(zip([0], [], [0])) result in?

This point still stands.

it'd be the partial results. by the time zip sees the StopIteration it has only seen the first iterator, so you get (0,) and the third iterator doesn't advance.

if you had stored the third iterator somewhere, you'd be able to call next on it directly as well.

_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/[email protected]/message/BBDE2XE57JZOKT55WECYWYZCW7JLIWAN/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/CGBZDLSZCMC6C5HHN7ZN67RVFHBHRS7L/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to