Skip to content

Commit

Permalink
Drop async-timeout dependency on Python 3.11+ (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Aug 30, 2023
1 parent bd2d861 commit 205dd5e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions aiojobs/_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import traceback
from typing import TYPE_CHECKING, Coroutine, Generic, Optional, TypeVar

import async_timeout
if sys.version_info >= (3, 11):
from asyncio import timeout as asyncio_timeout
else:
from async_timeout import timeout as asyncio_timeout

if TYPE_CHECKING:
from ._scheduler import Scheduler
Expand Down Expand Up @@ -70,7 +73,7 @@ def set_name(self, name: str) -> None:
self._task.set_name(name)

async def _do_wait(self, timeout: Optional[float]) -> _T:
async with async_timeout.timeout(timeout):
async with asyncio_timeout(timeout):
# TODO: add a test for waiting for a pending coro
await self._started
assert self._task is not None # Task should have been created before this.
Expand Down Expand Up @@ -113,7 +116,7 @@ async def _close(self, timeout: Optional[float]) -> None:
# self._scheduler is None after _done_callback()
scheduler = self._scheduler
try:
async with async_timeout.timeout(timeout):
async with asyncio_timeout(timeout):
await self._task
except asyncio.CancelledError:
pass
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ packages = aiojobs
include_package_data = True

install_requires =
async-timeout >= 4.0.0
async-timeout >= 4.0.0 ; python_version < "3.11"

[options.extras_require]
aiohttp =
Expand Down
9 changes: 7 additions & 2 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import asyncio
import sys
from typing import Awaitable, Callable, List, NoReturn
from unittest import mock

import pytest
from async_timeout import timeout

from aiojobs import Scheduler

if sys.version_info >= (3, 11):
from asyncio import timeout as asyncio_timeout
else:
from async_timeout import timeout as asyncio_timeout

_MakeScheduler = Callable[..., Awaitable[Scheduler]]


Expand Down Expand Up @@ -285,7 +290,7 @@ async def coro(fut: "asyncio.Future[None]") -> None:

with pytest.raises(asyncio.TimeoutError):
# try to wait for 1 sec to add task to pending queue
async with timeout(1):
async with asyncio_timeout(1):
await scheduler.spawn(coro(fut3))

assert scheduler.active_count == 1
Expand Down

0 comments on commit 205dd5e

Please sign in to comment.