Skip to content

Commit

Permalink
Reformat code to remove obsolete syntax (#538)
Browse files Browse the repository at this point in the history
Now the source is Python 3.9 compatible
  • Loading branch information
asvetlov authored Feb 10, 2025
1 parent 1281af3 commit b5baf39
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGES/538.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reformat the source to remove obsolete syntax; now it is python 3.9+ compatible.
5 changes: 2 additions & 3 deletions aiojobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ async def create_scheduler(
close_timeout: Optional[float] = 0.1,
limit: Optional[int] = 100,
pending_limit: int = 10000,
exception_handler: Optional[ExceptionHandler] = None
exception_handler: Optional[ExceptionHandler] = None,
) -> Scheduler:
warnings.warn("Scheduler can now be instantiated directly.", DeprecationWarning)

if exception_handler is not None and not callable(exception_handler):
raise TypeError(
"A callable object or None is expected, "
"got {!r}".format(exception_handler)
f"A callable object or None is expected, got {exception_handler!r}"
)
return Scheduler(
close_timeout=close_timeout,
Expand Down
5 changes: 3 additions & 2 deletions aiojobs/_job.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio
import sys
import traceback
from typing import TYPE_CHECKING, Coroutine, Generic, Optional, TypeVar
from collections.abc import Coroutine
from typing import TYPE_CHECKING, Generic, Optional, TypeVar

if sys.version_info >= (3, 11):
from asyncio import timeout as asyncio_timeout
Expand Down Expand Up @@ -31,7 +32,7 @@ def __init__(

self._closed = False
self._explicit = False
self._task: Optional["asyncio.Task[_T]"] = None
self._task: Optional[asyncio.Task[_T]] = None

tb = traceback.extract_stack(sys._getframe(2)) if loop.get_debug() else None
self._source_traceback = tb
Expand Down
10 changes: 3 additions & 7 deletions aiojobs/_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import asyncio
import sys
from collections.abc import Awaitable, Collection, Coroutine, Iterator
from contextlib import suppress
from types import TracebackType
from typing import (
Any,
Awaitable,
Callable,
Collection,
Coroutine,
Dict,
Iterator,
Optional,
Set,
Type,
Expand Down Expand Up @@ -44,8 +41,7 @@ def __init__(
):
if exception_handler is not None and not callable(exception_handler):
raise TypeError(
"A callable object or None is expected, "
"got {!r}".format(exception_handler)
f"A callable object or None is expected, got {exception_handler!r}"
)

self._jobs: Set[Job[object]] = set()
Expand All @@ -57,7 +53,7 @@ def __init__(
self._failed_tasks: asyncio.Queue[Optional[asyncio.Task[object]]] = (
asyncio.Queue()
)
self._failed_task: Optional["asyncio.Task[None]"] = None
self._failed_task: Optional[asyncio.Task[None]] = None
if sys.version_info < (3, 10):
self._failed_task = asyncio.create_task(self._wait_failed())
self._pending: asyncio.Queue[Job[object]] = asyncio.Queue(maxsize=pending_limit)
Expand Down
4 changes: 1 addition & 3 deletions aiojobs/aiohttp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import asyncio
from collections.abc import AsyncIterator, Awaitable, Coroutine
from functools import wraps
from typing import (
Any,
AsyncIterator,
Awaitable,
Callable,
Coroutine,
Optional,
TypeVar,
Union,
Expand Down
12 changes: 8 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import asyncio
from typing import Any, AsyncIterator, Awaitable, Callable, Dict
from collections.abc import AsyncIterator, Awaitable
from typing import Any, Callable, Dict

import pytest

from aiojobs import Scheduler

PARAMS: Dict[str, Any] = dict(
close_timeout=1.0, limit=100, pending_limit=0, exception_handler=None
)
PARAMS: Dict[str, Any] = {
"close_timeout": 1.0,
"limit": 100,
"pending_limit": 0,
"exception_handler": None,
}


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion tests/test_aiohttp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
from typing import Awaitable, Callable
from collections.abc import Awaitable
from typing import Callable

import pytest
from aiohttp import ClientSession, web
Expand Down
3 changes: 2 additions & 1 deletion tests/test_job.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from collections.abc import Awaitable
from contextlib import suppress
from typing import Awaitable, Callable, NoReturn
from typing import Callable, NoReturn
from unittest import mock

import pytest
Expand Down
21 changes: 11 additions & 10 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import sys
from typing import Awaitable, Callable, List, NoReturn
from collections.abc import Awaitable
from typing import Callable, List, NoReturn
from unittest import mock

import pytest
Expand Down Expand Up @@ -315,9 +316,9 @@ async def test_pending_queue_infinite(make_scheduler: _MakeScheduler) -> None:
async def coro(fut: "asyncio.Future[None]") -> None:
await fut

fut1: "asyncio.Future[None]" = asyncio.Future()
fut2: "asyncio.Future[None]" = asyncio.Future()
fut3: "asyncio.Future[None]" = asyncio.Future()
fut1: asyncio.Future[None] = asyncio.Future()
fut2: asyncio.Future[None] = asyncio.Future()
fut3: asyncio.Future[None] = asyncio.Future()

await scheduler.spawn(coro(fut1))
assert scheduler.pending_count == 0
Expand All @@ -336,9 +337,9 @@ async def coro(fut: "asyncio.Future[None]") -> None:
await asyncio.sleep(0)
await fut

fut1: "asyncio.Future[None]" = asyncio.Future()
fut2: "asyncio.Future[None]" = asyncio.Future()
fut3: "asyncio.Future[None]" = asyncio.Future()
fut1: asyncio.Future[None] = asyncio.Future()
fut2: asyncio.Future[None] = asyncio.Future()
fut3: asyncio.Future[None] = asyncio.Future()

await scheduler.spawn(coro(fut1))
assert scheduler.active_count == 1
Expand All @@ -365,7 +366,7 @@ async def test_scheduler_concurrency_pending_limit(
async def coro(fut: "asyncio.Future[object]") -> None:
await fut

futures: List["asyncio.Future[object]"] = [asyncio.Future() for _ in range(3)]
futures: List[asyncio.Future[object]] = [asyncio.Future() for _ in range(3)]
jobs = []

async def spawn() -> None:
Expand Down Expand Up @@ -402,14 +403,14 @@ async def coro(fut: "asyncio.Future[None]") -> None:
assert scheduler.active_count == 0
assert scheduler.pending_count == 0

fut1: "asyncio.Future[None]" = asyncio.Future()
fut1: asyncio.Future[None] = asyncio.Future()
job1 = await scheduler.spawn(coro(fut1))

assert scheduler.active_count == 1
assert scheduler.pending_count == 0
assert job1.active

fut2: "asyncio.Future[None]" = asyncio.Future()
fut2: asyncio.Future[None] = asyncio.Future()
job2 = await scheduler.spawn(coro(fut2))

assert scheduler.active_count == 1
Expand Down

0 comments on commit b5baf39

Please sign in to comment.