Re: [Python-ideas] Proposal: allow length_hint to specify infinite iterators

2017-11-29 Thread Antoine Pitrou
On Wed, 29 Nov 2017 09:39:57 +0200 Serhiy Storchaka 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

Re: [Python-ideas] Proposal: allow length_hint to specify infinite iterators

2017-11-28 Thread Serhiy Storchaka
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 t

[Python-ideas] Proposal: allow length_hint to specify infinite iterators

2017-11-28 Thread Steven D'Aprano
PEP 424 allows iterators to optionally offer a hint as to how long they will be: https://www.python.org/dev/peps/pep-0424/ Unfortunately, there's no good way for an iterator to report that it is infinitely long. Consequently, even those which are known to be infinite report finite lengths: p