Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test showing issue with PyExc_StopIteration #4810

Open
wants to merge 3 commits into
base: branch/py3.10
Choose a base branch
from

Conversation

gitlab-importer
Copy link

In GitLab by @rtobar on Jul 19, 2023, 05:59

This test shows that, depending on how a StopIteration object is built in a C
extension, the final result of an awaitable is visible or not at the python
layer.

The exception is "raised" by calling PyExc_SetObject(PyExc_StopIteration,
value). When "value" is an instance of PyExc_StopIteration that has already
been constructed with a value (i.e., "PyObject_CallOneArg(PyExc_StopIteration,
x)") then the exception is seen as expected, and the final value "x" is seen.
However, when "value" is "x" itself, the python layer gets a None object
instead. This difference in construction of exceptions in C extensions
(normalised v/s non-normalised exceptions) works seamlesly in CPython, but
doesn't in PyPy.

Note however that while developing this test and making it as minimal as
possible, I played with a simpler C extension that had a generator, and using
"yield from" from the python layer. That did work in both cases. This suggests
that the issue is specific to how coroutines are handled in PyPy.

--HG--
branch : stopiteration-issue

This test shows that, depending on how a StopIteration object is built in a C
extension, the final result of an awaitable is visible or not at the python
layer.

The exception is "raised" by calling PyExc_SetObject(PyExc_StopIteration,
value).  When "value" is an instance of PyExc_StopIteration that has already
been constructed with a value (i.e., "PyObject_CallOneArg(PyExc_StopIteration,
x)") then the exception is seen as expected, and the final value "x" is seen.
However, when "value" is "x" itself, the python layer gets a None object
instead. This difference in construction of exceptions in C extensions
(normalised v/s non-normalised exceptions) works seamlesly in CPython, but
doesn't in PyPy.

Note however that while developing this test and making it as minimal as
possible, I played with a simpler C extension that had a generator, and using
"yield from" from the python layer. That *did* work in both cases. This suggests
that the issue is specific to how coroutines are handled in PyPy.
@gitlab-importer
Copy link
Author

In GitLab by @rtobar on Jul 20, 2023, 10:30

added 1 commit

  • 19194e74 - Don't require asyncio to reproduce the error

Compare with previous version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants