PyIter_Next clears a StopException, where tp_iternext does not #29
Labels
stakeholder: alternative implementations
impacts implementations of python other than cpython
stakeholder: code generator devs
impacts projects that generate python code (like cython, pybind11, ...)
theme: consistency
theme: implementation flaws
problems with the implementation of specific APIs
Consider this code:
There are two ways to convert
next(an)
to C: eitherPyIter_Next(an)
oran.tp_iternext()
. There is a subtle difference:PyIter_Next
will return NULL, signaling that the iteration is complete, and clear theStopIteration
exception, erasing theex.args
. Callingtp_iternext
will not clear the exception, so theyield
value will be available through theex.args
. This came up in cython since it tends not to use the slot functions on non-CPython (in this case PyPy). As far as I can tell, there is noPyIter_*
function to only calltp_iternext
without clearing the exception.The text was updated successfully, but these errors were encountered: