Message324119
That's the documented behavior. Per https://docs.python.org/3/reference/datamodel.html#object.__getitem__ :
>Note: for loops expect that an IndexError will be raised for illegal indexes to allow proper detection of the end of the sequence.
The need for *only* __getitem__ is also mentioned in the documentation of the iter builtin ( https://docs.python.org/3/library/functions.html#iter ):
>Without a second argument, object must be a collection object which supports the iteration protocol (the __iter__() method), or it must support the sequence protocol (the __getitem__() method with integer arguments starting at 0).
At no point is a dependency on __len__ mentioned. |
|
Date |
User |
Action |
Args |
2018-08-26 14:43:43 | josh.r | set | recipients:
+ josh.r, rhettinger, Eric.Wieser, prudvinit, treddy |
2018-08-26 14:43:43 | josh.r | set | messageid: <1535294623.33.0.56676864532.issue34494@psf.upfronthosting.co.za> |
2018-08-26 14:43:43 | josh.r | link | issue34494 messages |
2018-08-26 14:43:43 | josh.r | create | |
|