-
Notifications
You must be signed in to change notification settings - Fork 6
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
Description
Consider this code:
async def gen():
yield 123
def test_last_yield(g):
ai = g.__aiter__()
an = ai.__anext__()
try:
next(an)
except StopIteration as ex:
return ex.args
else:
return None
ret = test_last_yield(gen())
assert ret[0] == 123There are two ways to convert next(an) to C: either PyIter_Next(an) or an.tp_iternext(). There is a subtle difference: PyIter_Next will return NULL, signaling that the iteration is complete, and clear the StopIteration exception, erasing the ex.args. Calling tp_iternext will not clear the exception, so the yield value will be available through the ex.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 no PyIter_* function to only call tp_iternext without clearing the exception.
Reactions are currently unavailable
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