On 2020-04-21 12:01 p.m., Soni L. wrote:


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.



looking further into it, zip() already guarantees the StopIteration isn't gonna preserve the original StopIteration, so this should be a non-breaking change:

https://docs.python.org/3/library/functions.html#zip

Equivalent to:
def  zip(*iterables):
     # zip('ABCD', 'xy') --> Ax By
     sentinel  =  object()
     iterators  =  [iter(it)  for  it  in  iterables]
     while  iterators:
         result  =  []
         for  it  in  iterators:
             elem  =  next(it,  sentinel)
             if  elem  is  sentinel:
                 return
             result.append(elem)
         yield  tuple(result)

my proposal is to change that "return" into "return tuple(result)".


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


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

Reply via email to