[Python-Dev] issue with itertools leads the crash

Steven D'Aprano steve at pearwood.info
Thu Apr 10 02:55:01 CEST 2014


On Wed, Apr 09, 2014 at 02:40:21PM -0400, Geoffrey Spear wrote:

> Of course, this raises the question of whether making slice assignment
> not go into an infinite loop when the programmer asks it to is a
> bugfix or a new feature.

Definitely a new feature.

> Calling:
> 
>     list(itertools.cycle([0]))
> 
> exhibits the same behavior for the same reason, and I don't think
> anyone would call that a bug in Python.

It's not a bug, nevertheless it is a problem that can be amiliated. 
Some objects now have a __length_hint__  method. cycle could use that to 
indicate that it was infinitely long, and list could raise an exception 
*before* consuming all available memory.

http://legacy.python.org/dev/peps/pep-0424/


-- 
Steven


More information about the Python-Dev mailing list