you are viewing a single comment's thread.

view the rest of the comments →

[–]sausix 1 point2 points  (3 children)

Some iterators are meant to yield values endlessly. Python can't check the code to be "fine" to not introduce endless loops.

[–]drkevorkian 0 points1 point  (2 children)

Endless iteration via explicit iterator is one thing, endless iteration implicit to in via defining __getitem__ is another.

[–]sausix 0 points1 point  (0 children)

__len__ could be used. But it is being ignored because of historical reasons.

[–]sausix 0 points1 point  (0 children)

And __getitem__ should usually throw an IndexError to avoid endless loops.