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

Fix #930: suppress CancelledError when Timeout raises TimeoutError #970

Merged
merged 1 commit into from
Jul 16, 2016
Merged
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
2 changes: 1 addition & 1 deletion aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is asyncio.CancelledError and self._cancelled:
self._cancel_handler = None
self._task = None
raise asyncio.TimeoutError
raise asyncio.TimeoutError from None
if self._timeout is not None:
self._cancel_handler.cancel()
self._cancel_handler = None
Expand Down
10 changes: 10 additions & 0 deletions tests/test_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,13 @@ def outer():
yield from task
assert task.cancelled()
assert task.done()


@pytest.mark.run_loop
def test_timeout_suppress_exception_chain(loop):

with pytest.raises(asyncio.TimeoutError) as ctx:
with Timeout(0.01, loop=loop) as t:
yield from asyncio.sleep(10, loop=loop)
assert t._loop is loop
assert ctx.value.__suppress_context__