On Wed, 29 Nov 2017 09:39:57 +0200 Serhiy Storchaka <storch...@gmail.com> wrote: > 29.11.17 03:34, Steven D'Aprano пише: > > This wastes the opportunity to fail fast on operations which cannot > > possibly succeed, e.g. list(count()) must eventually fail with > > MemoryError. Or worse: if the OS starts thrashing trying to meet the > > memory requests, you can lock up the computer. > > > > I propose that we: > > > > (1) extend the __length_hint__ protocol to allow iterators to report > > that they are infinite; > > > > (2) and recommend that consumers of iterators (such as list) that > > require finite input should fail fast in the event of an infinite > > iterator. > > Infinite iterators are rare. And count() is even more special in the > sense that iterating it doesn't have side effects and is not interruptible.
Not to mention that many infinite iterators cannot be predicted in advance to be infinite. Only the more trivial cases such as count() would apply (but not a takewhile() involving count(), for example). Regards Antoine. _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/