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')
--- /dev/null
+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.