Skip to content

Commit 205dd5e

Browse files
Drop async-timeout dependency on Python 3.11+ (#443)
1 parent bd2d861 commit 205dd5e

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

aiojobs/_job.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import traceback
44
from typing import TYPE_CHECKING, Coroutine, Generic, Optional, TypeVar
55

6-
import async_timeout
6+
if sys.version_info >= (3, 11):
7+
from asyncio import timeout as asyncio_timeout
8+
else:
9+
from async_timeout import timeout as asyncio_timeout
710

811
if TYPE_CHECKING:
912
from ._scheduler import Scheduler
@@ -70,7 +73,7 @@ def set_name(self, name: str) -> None:
7073
self._task.set_name(name)
7174

7275
async def _do_wait(self, timeout: Optional[float]) -> _T:
73-
async with async_timeout.timeout(timeout):
76+
async with asyncio_timeout(timeout):
7477
# TODO: add a test for waiting for a pending coro
7578
await self._started
7679
assert self._task is not None # Task should have been created before this.
@@ -113,7 +116,7 @@ async def _close(self, timeout: Optional[float]) -> None:
113116
# self._scheduler is None after _done_callback()
114117
scheduler = self._scheduler
115118
try:
116-
async with async_timeout.timeout(timeout):
119+
async with asyncio_timeout(timeout):
117120
await self._task
118121
except asyncio.CancelledError:
119122
pass

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ packages = aiojobs
4646
include_package_data = True
4747

4848
install_requires =
49-
async-timeout >= 4.0.0
49+
async-timeout >= 4.0.0 ; python_version < "3.11"
5050

5151
[options.extras_require]
5252
aiohttp =

tests/test_scheduler.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import asyncio
2+
import sys
23
from typing import Awaitable, Callable, List, NoReturn
34
from unittest import mock
45

56
import pytest
6-
from async_timeout import timeout
77

88
from aiojobs import Scheduler
99

10+
if sys.version_info >= (3, 11):
11+
from asyncio import timeout as asyncio_timeout
12+
else:
13+
from async_timeout import timeout as asyncio_timeout
14+
1015
_MakeScheduler = Callable[..., Awaitable[Scheduler]]
1116

1217

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

286291
with pytest.raises(asyncio.TimeoutError):
287292
# try to wait for 1 sec to add task to pending queue
288-
async with timeout(1):
293+
async with asyncio_timeout(1):
289294
await scheduler.spawn(coro(fut3))
290295

291296
assert scheduler.active_count == 1

0 commit comments

Comments
 (0)