On 22.04.20 11:19, Steven D'Aprano wrote:

On Wed, Apr 22, 2020 at 10:52:44AM +0200, Dominik Vilsmeier wrote:

You can basically use the code from this StackOverflow answer (code
attached below) to cache the last object yielded by each iterator:
https://stackoverflow.com/a/61126744
Caching the result of iterators is unsafe if the value yielded depends
on the environment at the time. It can leave you vulnerable to Time Of
Check To Time Of Use bugs, or inaccurate results.



Good point, but in this case it only caches the most recently yielded
value. It's the value that would have ended up in a tuple during `zip`
if not one of the other iterators had stopped the iteration. So whatever
state the environment is in, it still corresponds to those cached
values. How this partial result is then used is a different question.
_______________________________________________
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/27K2DBLAVAO4VXWUQFRPWLZHU54N2T6T/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to