This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author methane
Recipients Aaron Hall, anthony shaw, methane, ncoghlan, pablogsal, ronaldoussoren, serhiy.storchaka
Date 2019-04-08.11:45:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAEfz+TzZxqjU4ijv+wS5m_6p6fm44VqtQNcS-XZs=VhkdSc+Ag@mail.gmail.com>
In-reply-to <1554723417.93.0.539341851135.issue36551@roundup.psfhosted.org>
Content
> > This might cause a MemoryError when the __length_hint__ of the source returns a too large value, even when the actual size of the comprehension is smaller, e.g.:
>
> The current implementation of list comprehensions raise neither a memoryerror or overflow error. They will consume all available memory and crash the interpreter.
>
> This patch raises an OverflowError before execution instead of just looping until memory heap exhaustion
>

Note PEP 424.

"""
__length_hint__ must return an integer (else a TypeError is raised) or
NotImplemented, and is not required to be accurate. It may return a
value that is either larger or smaller than the actual size of the
container.
"""

it.__length_hint__ can return 2**1000 even if len(list(it))==0.

In such case, current behavior works.  And your patch will raise OverflowError.
History
Date User Action Args
2019-04-08 11:45:13methanesetrecipients: + methane, ronaldoussoren, ncoghlan, serhiy.storchaka, Aaron Hall, pablogsal, anthony shaw
2019-04-08 11:45:13methanelinkissue36551 messages
2019-04-08 11:45:13methanecreate