Josh Rosenberg added the comment:

I think it avoids len because the length might change during iteration due to 
side-effects of other code. Since a shrinking sequence would raise an 
IndexError anyway when you overran the end, it may as well not assume the 
length is static and just keep indexing forward until it hits an IndexError. 
It's less of an issue (though not a non-issue) with index, because index 
actually performs all the indexing without returning to user code; __iter__ 
pauses to allow user code to execute between each yield, so the odds of a 
length mutation are much higher.

You might be able to use len (and just say that if a side-effect of an equality 
comparison causes the sequence to change length, or another thread messes with 
it, that's your own fault), but you'd probably want  to catch and convert 
IndexError to ValueError to consistently respond to "we didn't find it" with 
the same exception.

----------
nosy: +josh.r

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23086>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to