[issue26828] Implement __length_hint__() on map() and filter() to optimize list(map) and list(filter)

Michael Seifert report at bugs.python.org
Wed Apr 26 10:54:44 EDT 2017


Michael Seifert added the comment:

> zip.__length_hint__() must return NotImplemented or raise TypeError if any of iterators don't implement __length_hint__ or its __length_hint__() returns NotImplemented or raises TypeError.

> And what should return zip(range(3), range(2**1000)).__length_hint__()? I expect 3, not OverflowError.

That's actually non-trivial because PyObject_LengthHint just returns a Py_ssize_t. To recover NotImplemented will be complicated and there's no way to discriminate if the OverflowError happened in PyObject_LengthHint or in the called __length_hint__. 

But TypeError is correctly re-raised in the tests I made.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26828>
_______________________________________


More information about the Python-bugs-list mailing list