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.

classification
Title: An errornous __length_hint__ can make list() raise a SystemError
Type: behavior Stage:
Components: Versions: Python 3.0, Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: alexandre.vassalotti, christian.heimes, rhettinger
Priority: normal Keywords:

Created on 2007-12-04 05:43 by alexandre.vassalotti, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg58176 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2007-12-04 05:43
If an iterator with a __length_hint__ method that returns a negative
integer is passed to list(), a SystemError is raised.

>>> class A:
...     def __iter__(self):
...         return self
...     def __length_hint__(self):
...         return -1
... 
>>> list(A())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: NULL result without error in PyObject_Call
msg58178 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2007-12-04 06:22
Fixed for Py3k in r59316.

Should this gets backported?
msg58208 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-12-05 06:43
Please post the patch here.  I'll take a look to see if it should be 
backported.
msg58213 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-05 12:54
I've backported the fix to 2.5 and trunk. They suffered from the same
problem.
History
Date User Action Args
2022-04-11 14:56:28adminsetgithub: 45894
2007-12-05 12:54:32christian.heimessetstatus: open -> closed
resolution: fixed
messages: + msg58213
nosy: + christian.heimes
2007-12-05 06:43:39rhettingersetassignee: rhettinger
messages: + msg58208
nosy: + rhettinger
2007-12-05 02:48:33alexandre.vassalottisetstatus: open
2007-12-04 06:22:33alexandre.vassalottisetstatus: open -> (no value)
messages: + msg58178
2007-12-04 05:43:57alexandre.vassalotticreate