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 eff0c64
Showing 1 changed file with 8 additions and 1 deletion.
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 eff0c64

Please sign in to comment.