-
Notifications
You must be signed in to change notification settings - Fork 6
PyIter_Next clears a StopException, where tp_iternext does not #29
Copy link
Copy link
Open
Labels
stakeholder: alternative implementationsimpacts implementations of python other than cpythonimpacts implementations of python other than cpythonstakeholder: code generator devsimpacts projects that generate python code (like cython, pybind11, ...)impacts projects that generate python code (like cython, pybind11, ...)theme: consistencytheme: implementation flawsproblems with the implementation of specific APIsproblems with the implementation of specific APIs
Metadata
Metadata
Assignees
Labels
stakeholder: alternative implementationsimpacts implementations of python other than cpythonimpacts implementations of python other than cpythonstakeholder: code generator devsimpacts projects that generate python code (like cython, pybind11, ...)impacts projects that generate python code (like cython, pybind11, ...)theme: consistencytheme: implementation flawsproblems with the implementation of specific APIsproblems 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_Nextwill return NULL, signaling that the iteration is complete, and clear theStopIterationexception, erasing theex.args. Callingtp_iternextwill not clear the exception, so theyieldvalue 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_iternextwithout clearing the exception.