On Wed, Apr 22, 2020 at 12:25 AM Eric V. Smith <e...@trueblade.com> 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.

Very minor bikeshedding: Since args is normally going to have a
predictable length, I think it'd be better to declare that the first
argument is a truncated tuple. That means wrapping it up in one more
level of tuple, but in return, the raised exception has the option to
have other arguments added in the future.

Alternatively, StopIteration already has a 'value' attribute (used for
the return value of a generator). Would it be better to use that
rather than the args? Currently, it retains any value that was already
in it - so if the shortest iterable is a generator, then its return
value will be in the propagated StopIteration. Not sure if that's a
guarantee and therefore covered by backward compatibility.

ChrisA
_______________________________________________
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/MXBV6HVHHCCSMIS4ZCJVS6XLENS3YU5D/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to