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.

(c) take the convention that returning sys.maxint means infinity;

Returning sys.maxsize will likely lead to failing fast with MemoryError.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to