This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients Devin Jeanpierre, josh.r, rhettinger
Date 2015-01-08.22:44:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1420757050.69.0.76274419584.issue23086@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-01-08 22:44:10josh.rsetrecipients: + josh.r, rhettinger, Devin Jeanpierre
2015-01-08 22:44:10josh.rsetmessageid: <1420757050.69.0.76274419584.issue23086@psf.upfronthosting.co.za>
2015-01-08 22:44:10josh.rlinkissue23086 messages
2015-01-08 22:44:10josh.rcreate