Oddity with Iteration and len in Python 2.6 / 3.0

This issue was raised by Dino Veihland (core developer of IronPython) when asking whether IronPython should implement a particular behavior of CPython that seemed a bit odd. This in turn was triggered by an IronPython bug report.

So you can see that when you create an iterator from an object, __len__ is called - as an optimisation for the interpreter. As it is only called as an optimisation it was implemented in a way that exceptions whilst calling __len__ (or __length_hint__) as a side-effect of creating an iterator won't stop the iterator being created. Even to the extent of ignoring an explicit call to sys.exit()!

Unfortunately that can have the side effect of masking errors in your code - so after a bit of thought Guido has decided that this is a misfeature (a bug) that will be fixed. Another reminder that having multiple implementations is good for a language - design decisions get revisited 'in the cold light of day' as they are reimplemented.