Skip to content

Commit

Permalink
Add distinction between error cases in TimerContext
Browse files Browse the repository at this point in the history
  • Loading branch information
GDYendell committed Dec 11, 2024
1 parent 3f07b1a commit 6faaa4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Frederik Peter Aalund
Gabriel Tremblay
Gang Ji
Gary Wilson Jr.
Gary Yendell
Gennady Andreyev
Georges Dubus
Greg Holt
Expand Down
9 changes: 8 additions & 1 deletion aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,14 @@ def assert_timeout(self) -> None:
def __enter__(self) -> BaseTimerContext:
task = asyncio.current_task(loop=self._loop)
if task is None:
raise RuntimeError("Timeout context manager should be used inside a task")
if asyncio.current_task() is not None:
raise RuntimeError(

Check warning on line 662 in aiohttp/helpers.py

View check run for this annotation

Codecov / codecov/patch

aiohttp/helpers.py#L662

Added line #L662 was not covered by tests
"Timeout context manager used in a task on a different event loop"
)
else:
raise RuntimeError(

Check warning on line 666 in aiohttp/helpers.py

View check run for this annotation

Codecov / codecov/patch

aiohttp/helpers.py#L666

Added line #L666 was not covered by tests
"Timeout context manager should be used inside a task"
)

if sys.version_info >= (3, 11):
# Remember if the task was already cancelling
Expand Down

0 comments on commit 6faaa4d

Please sign in to comment.