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: PyIter_Check evaluates to 0 for Python list object
Type: Stage:
Components: None Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, brett.cannon, tromey
Priority: normal Keywords:

Created on 2012-08-01 16:40 by tromey, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg167143 - (view) Author: Tom Tromey (tromey) Date: 2012-08-01 16:40
I was debugging this bug reported against gdb:

http://sourceware.org/bugzilla/show_bug.cgi?id=14386

It turns out that what went wrong in this code was that
PyIter_Check evaluates to 0 when its argument is a
Python list.

This happens because the PyIter_Check macro looks at the
tp_iternext field; but this field is 0 in PyList_Type.

I am not sure of the correct fix; but PyIter_Check is not
faithfully reflecting what PyObject_GetIter does.
Maybe it isn't intended to; but anyway it seems that
checking tp_iter would maybe be a better approximation.

Even if PyIter_Check remains as-is, I think it would be nice
if the documentation were more specific about what it
actually does.

FWIW I'm modifying gdb not to use this function.
msg167144 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-08-01 16:42
That's because lists are iterators not iterable.
msg167164 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-08-01 19:22
I think Benjamin meant to say lists are iterables not iterators. =)
History
Date User Action Args
2022-04-11 14:57:33adminsetgithub: 59734
2012-08-01 19:22:22brett.cannonsetnosy: + brett.cannon
messages: + msg167164
2012-08-01 16:43:00benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg167144

resolution: not a bug
2012-08-01 16:40:30tromeycreate