[issue36551] Optimize list comprehensions with preallocate size and protect against overflow

anthony shaw report at bugs.python.org
Mon Apr 8 08:08:40 EDT 2019


anthony shaw <anthony.p.shaw at gmail.com> added the comment:

> If your patch uses __length_hint__, it is bug.
iterator will return 2**1000 for __length_hint__, but produce no item
on iteration.

It raises an OverflowError because of the goto
https://github.com/python/cpython/pull/12718/files#diff-7f17c8d8448b7b6f90549035d2147a9fR2493 this could just as easily set size to 0.

I put `goto error` given the opportunity to handle an expected fault gracefully.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36551>
_______________________________________


More information about the Python-bugs-list mailing list