Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Lib/test/test_asyncio/test_futures2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ async def raise_exc():
else:
self.fail('TypeError was not raised')

async def test_future_traceback_preserved_after_suppress(self):
async def raise_exc():
raise TypeError(42)

future = self.cls(raise_exc())
try:
await future
except TypeError:
pass

try:
await future
except TypeError as e:
tb = ''.join(traceback.format_tb(e.__traceback__))
self.assertIn('raise_exc', tb,
'Original raise site lost after first result() call')
else:
self.fail('TypeError was not raised')


async def test_task_exc_handler_correct_context(self):
# see https://github.com/python/cpython/issues/96704
name = contextvars.ContextVar('name', default='foo')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fix :class:`asyncio.Future` (C implementation) losing the initial exception
traceback frames when ``Future.result()`` is called more than once. Previously,
the C implementation cleared the stored traceback after the first call, causing
subsequent raises to omit the original raise site. The pure-Python
implementation was unaffected.
1 change: 0 additions & 1 deletion Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,6 @@ future_get_result(asyncio_state *state, FutureObj *fut, PyObject **result)
return -1;
}
*result = Py_NewRef(fut->fut_exception);
Py_CLEAR(fut->fut_exception_tb);
return 1;
}

Expand Down
Loading