Skip to content

Commit a77d4a4

Browse files
authored
Fix #930: suppress CancelledError when Timeout raises TimeoutError (#970)
1 parent 054a0f6 commit a77d4a4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

aiohttp/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
561561
if exc_type is asyncio.CancelledError and self._cancelled:
562562
self._cancel_handler = None
563563
self._task = None
564-
raise asyncio.TimeoutError
564+
raise asyncio.TimeoutError from None
565565
if self._timeout is not None:
566566
self._cancel_handler.cancel()
567567
self._cancel_handler = None

tests/test_timeout.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,13 @@ def outer():
165165
yield from task
166166
assert task.cancelled()
167167
assert task.done()
168+
169+
170+
@pytest.mark.run_loop
171+
def test_timeout_suppress_exception_chain(loop):
172+
173+
with pytest.raises(asyncio.TimeoutError) as ctx:
174+
with Timeout(0.01, loop=loop) as t:
175+
yield from asyncio.sleep(10, loop=loop)
176+
assert t._loop is loop
177+
assert ctx.value.__suppress_context__

0 commit comments

Comments
 (0)