Skip to content

[mypyc] Fix tracebacks of exceptions passed to throw() - #22287

Open
p-sawicki wants to merge 2 commits into
python:masterfrom
p-sawicki:fix-coroutine-throw-tb
Open

p-sawicki wants to merge 2 commits into
python:masterfrom
p-sawicki:fix-coroutine-throw-tb

Conversation

@p-sawicki

Copy link
Copy Markdown
Collaborator

When calling single-argument throw(ex) on a coroutine or generator, the traceback argument is None, so passing it to PyErr_Restore clears the existing exception traceback. Recover the traceback from the exception instead to match interpreted Python.

Don't add a traceback entry when forwarding an exception injected through throw() at await/yield from. Otherwise, the child coro/gen would see the parent's frame in its traceback. The parent's entry is still added when propagating the exception, so this also avoids a duplicated entry.

p-sawicki added a commit that referenced this pull request Oct 26, 2026
#22287 makes mypyc no longer add the parent's frame to the traceback
before forwarding an exception injected with `throw()` to an awaited
coroutine.

This means that the traceback can be empty and we might call
`throw(type, exception, None)` which incorrectly results in a type error
on Python 3.11.1 as seen in
[CI](https://github.com/python/mypy/actions/runs/39997005770/job/120563034921?pr=22287).
Relevant issue: python/cpython#101326.

Use newer Python 3.11 version in the 32-bit job which includes a fix.
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.

1 participant