[issue34494] simple "sequence" class ignoring __len__

2018-08-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: I concur with Josh. This matches the documented behavior and isn't a bug. Marking as closed. There are potentially two ways to stop sequence iteration, either by using len or by waiting for IndexError. Python uses the latter to allow lists to be dynami

[issue34494] simple "sequence" class ignoring __len__

2018-08-26 Thread Josh Rosenberg
Josh Rosenberg added the comment: 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 *o

[issue34494] simple "sequence" class ignoring __len__

2018-08-25 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: -> rhettinger nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue34494] simple "sequence" class ignoring __len__

2018-08-25 Thread Eric Wieser
Eric Wieser added the comment: What I think I find surprising is that I'd expect the sequence protocol to be defined by `__getitem__` and `__len__`, and for `__iter__` to be inferred as: def __iter__(self): for i in range(len(self)): yield self[i] But in reality it se

[issue34494] simple "sequence" class ignoring __len__

2018-08-25 Thread Eric Wieser
Change by Eric Wieser : -- nosy: +Eric.Wieser ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.py

[issue34494] simple "sequence" class ignoring __len__

2018-08-25 Thread Prudvi RajKumar Maddala
Prudvi RajKumar Maddala added the comment: I think it should hang, since we are not throwing any StopIteration exception to break the infinite loop -- nosy: +prudvinit ___ Python tracker ___

[issue34494] simple "sequence" class ignoring __len__

2018-08-24 Thread Tyler Reddy
New submission from Tyler Reddy : Downstream in NumPy we've noticed that a "sequence" object defined as below will hang (infinite __getitem__ calls) if we try to turn it into an array. The same holds in CPython for converting it to a list: class OneList: def __len__(self): # this