Roundup Robot added the comment:
New changeset 0f7795edca65 by Raymond Hettinger in branch '2.7':
Issue #24161: Document that PyIter_Check() returns false positives for
old-style instances.
https://hg.python.org/cpython/rev/0f7795edca65
--
nosy: +python-dev
Changes by Raymond Hettinger raymond.hettin...@gmail.com:
--
resolution: - fixed
status: open - closed
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24161
___
New submission from behzad nouri:
- python 2 only, not reproducible on python 3
Attached file makes an extension module which just returns PyIter_Check value
on passed object.
Calling the function with an object of type instance returns true, even
though the object is not iterator:
Raymond Hettinger added the comment:
The PyIter_Check() macro in Include/abstract.h does a quick test to see whether
the tp_iternext slot is null or marked as not implemented. That works for
builtin types but not for user defined classes (heap types).
Old-style instances, see
behzad nouri added the comment:
That works for builtin types but not for user defined classes
Rather than using PyIter_Check(), extensions should just call next() on
object and see whether it succeeds
but then, what would be the use case of PyIter_Check outside of python core?
--
Raymond Hettinger added the comment:
but then, what would be the use case of PyIter_Check
outside of python core?
You could still use it anywhere. It will give a correct result in the cases of
extension modules, builtin types, and new-style classes. It will give a false
positive in the
Changes by Raymond Hettinger raymond.hettin...@gmail.com:
--
keywords: +patch
Added file: http://bugs.python.org/file39338/doc_iter_check.diff
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24161