I am aware that there are very good reasons not to force __len__
to be part of the iterator
s' API (e.g. Understanding len function with iterators) and I do understand that the difference between an Iterable
and a Sequence
is mostly with the implementation of __len__
(e.g. What exactly does "iterable" mean in Python?).
However, I was wandering if there is a standard way of determining or at least naming "(in)finite" iterators, so that the need for avoiding infinite iterators is at least well-documented.
This would be useful if, for example, the code needs to iterate through all the elements of the Iterable
and waiting for the system to run out of memory is not an acceptable behavior for the software.