Skip to content

Commit e085d1c

Browse files
author
Nicolas Steinmetz
committed
fix: adjust linting
1 parent ebe5e5c commit e085d1c

File tree

7 files changed

+41
-38
lines changed

7 files changed

+41
-38
lines changed

arq/connections.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dataclasses import dataclass
55
from datetime import datetime, timedelta
66
from operator import attrgetter
7-
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Tuple, Union, cast
7+
from typing import TYPE_CHECKING, Any, Callable, Optional, Union, cast
88
from urllib.parse import parse_qs, urlparse
99
from uuid import uuid4
1010

@@ -28,7 +28,7 @@ class RedisSettings:
2828
Used by :func:`arq.connections.create_pool` and :class:`arq.worker.Worker`.
2929
"""
3030

31-
host: Union[str, List[Tuple[str, int]]] = 'localhost'
31+
host: Union[str, list[tuple[str, int]]] = 'localhost'
3232
port: int = 6379
3333
unix_socket_path: Optional[str] = None
3434
database: int = 0
@@ -50,7 +50,7 @@ class RedisSettings:
5050
sentinel_master: str = 'mymaster'
5151

5252
retry_on_timeout: bool = False
53-
retry_on_error: Optional[List[Exception]] = None
53+
retry_on_error: Optional[list[Exception]] = None
5454
retry: Optional[Retry] = None
5555

5656
@classmethod
@@ -189,7 +189,7 @@ async def _get_job_result(self, key: bytes) -> JobResult:
189189
r.job_id = job_id
190190
return r
191191

192-
async def all_job_results(self) -> List[JobResult]:
192+
async def all_job_results(self) -> list[JobResult]:
193193
"""
194194
Get results for all jobs in redis.
195195
"""
@@ -207,7 +207,7 @@ async def _get_job_def(self, job_id: bytes, score: int) -> JobDef:
207207
jd.job_id = job_id.decode()
208208
return jd
209209

210-
async def queued_jobs(self, *, queue_name: Optional[str] = None) -> List[JobDef]:
210+
async def queued_jobs(self, *, queue_name: Optional[str] = None) -> list[JobDef]:
211211
"""
212212
Get information about queued, mostly useful when testing.
213213
"""

arq/jobs.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from dataclasses import dataclass
66
from datetime import datetime
77
from enum import Enum
8-
from typing import Any, Callable, Dict, Optional, Tuple
8+
from typing import Any, Callable, Optional
99

1010
from redis.asyncio import Redis
1111

@@ -14,8 +14,8 @@
1414

1515
logger = logging.getLogger('arq.jobs')
1616

17-
Serializer = Callable[[Dict[str, Any]], bytes]
18-
Deserializer = Callable[[bytes], Dict[str, Any]]
17+
Serializer = Callable[[dict[str, Any]], bytes]
18+
Deserializer = Callable[[bytes], dict[str, Any]]
1919

2020

2121
class ResultNotFound(RuntimeError):
@@ -42,8 +42,8 @@ class JobStatus(str, Enum):
4242
@dataclass
4343
class JobDef:
4444
function: str
45-
args: Tuple[Any, ...]
46-
kwargs: Dict[str, Any]
45+
args: tuple[Any, ...]
46+
kwargs: dict[str, Any]
4747
job_try: int
4848
enqueue_time: datetime
4949
score: Optional[int]
@@ -210,8 +210,8 @@ class DeserializationError(SerializationError):
210210

211211
def serialize_job(
212212
function_name: str,
213-
args: Tuple[Any, ...],
214-
kwargs: Dict[str, Any],
213+
args: tuple[Any, ...],
214+
kwargs: dict[str, Any],
215215
job_try: Optional[int],
216216
enqueue_time_ms: int,
217217
*,
@@ -228,8 +228,8 @@ def serialize_job(
228228

229229
def serialize_result(
230230
function: str,
231-
args: Tuple[Any, ...],
232-
kwargs: Dict[str, Any],
231+
args: tuple[Any, ...],
232+
kwargs: dict[str, Any],
233233
job_try: int,
234234
enqueue_time_ms: int,
235235
success: bool,
@@ -291,7 +291,7 @@ def deserialize_job(r: bytes, *, deserializer: Optional[Deserializer] = None) ->
291291

292292
def deserialize_job_raw(
293293
r: bytes, *, deserializer: Optional[Deserializer] = None
294-
) -> Tuple[str, Tuple[Any, ...], Dict[str, Any], int, int]:
294+
) -> tuple[str, tuple[Any, ...], dict[str, Any], int, int]:
295295
if deserializer is None:
296296
deserializer = pickle.loads
297297
try:

arq/logs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import Any, Dict
1+
from typing import Any
22

33

4-
def default_log_config(verbose: bool) -> Dict[str, Any]:
4+
def default_log_config(verbose: bool) -> dict[str, Any]:
55
"""
66
Setup default config. for dictConfig.
77

arq/typing.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from collections.abc import Sequence
12
from datetime import timedelta
2-
from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Protocol, Sequence, Set, Type, Union
3+
from typing import TYPE_CHECKING, Any, Literal, Optional, Protocol, Union
34

45
__all__ = (
56
'OptionType',
@@ -16,7 +17,7 @@
1617
from .cron import CronJob
1718
from .worker import Function
1819

19-
OptionType = Union[None, Set[int], int]
20+
OptionType = Union[None, set[int], int]
2021
WEEKDAYS = 'mon', 'tues', 'wed', 'thurs', 'fri', 'sat', 'sun'
2122
WeekdayOptionType = Union[OptionType, Literal['mon', 'tues', 'wed', 'thurs', 'fri', 'sat', 'sun']]
2223
SecondsTimedelta = Union[int, float, timedelta]
@@ -25,14 +26,14 @@
2526
class WorkerCoroutine(Protocol):
2627
__qualname__: str
2728

28-
async def __call__(self, ctx: Dict[Any, Any], *args: Any, **kwargs: Any) -> Any: # pragma: no cover
29+
async def __call__(self, ctx: dict[Any, Any], *args: Any, **kwargs: Any) -> Any: # pragma: no cover
2930
pass
3031

3132

3233
class StartupShutdown(Protocol):
3334
__qualname__: str
3435

35-
async def __call__(self, ctx: Dict[Any, Any]) -> Any: # pragma: no cover
36+
async def __call__(self, ctx: dict[Any, Any]) -> Any: # pragma: no cover
3637
pass
3738

3839

@@ -44,4 +45,4 @@ class WorkerSettingsBase(Protocol):
4445
# and many more...
4546

4647

47-
WorkerSettingsType = Union[Dict[str, Any], Type[WorkerSettingsBase]]
48+
WorkerSettingsType = Union[dict[str, Any], type[WorkerSettingsBase]]

arq/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import asyncio
22
import logging
33
import os
4+
from collections.abc import AsyncGenerator, Sequence
45
from datetime import datetime, timedelta, timezone
56
from functools import lru_cache
67
from time import time
7-
from typing import TYPE_CHECKING, Any, AsyncGenerator, Dict, Optional, Sequence, overload
8+
from typing import TYPE_CHECKING, Any, Optional, overload
89

910
from .constants import timezone_env_vars
1011

@@ -121,7 +122,7 @@ def truncate(s: str, length: int = DEFAULT_CURTAIL) -> str:
121122
return s
122123

123124

124-
def args_to_string(args: Sequence[Any], kwargs: Dict[str, Any]) -> str:
125+
def args_to_string(args: Sequence[Any], kwargs: dict[str, Any]) -> str:
125126
arguments = ''
126127
if args:
127128
arguments = ', '.join(map(repr, args))

arq/worker.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import inspect
44
import logging
55
import signal
6+
from collections.abc import Sequence
67
from dataclasses import dataclass
78
from datetime import datetime, timedelta, timezone
89
from functools import partial
910
from signal import Signals
1011
from time import time
11-
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Sequence, Set, Tuple, Union, cast
12+
from typing import TYPE_CHECKING, Any, Callable, Optional, Union, cast
1213

1314
from redis.exceptions import ResponseError, WatchError
1415

@@ -118,7 +119,7 @@ def __eq__(self, other: Any) -> bool:
118119

119120

120121
class FailedJobs(RuntimeError):
121-
def __init__(self, count: int, job_results: List[JobResult]):
122+
def __init__(self, count: int, job_results: list[JobResult]):
122123
self.count = count
123124
self.job_results = job_results
124125

@@ -208,7 +209,7 @@ def __init__(
208209
max_tries: int = 5,
209210
health_check_interval: 'SecondsTimedelta' = 3600,
210211
health_check_key: Optional[str] = None,
211-
ctx: Optional[Dict[Any, Any]] = None,
212+
ctx: Optional[dict[Any, Any]] = None,
212213
retry_jobs: bool = True,
213214
allow_abort_jobs: bool = False,
214215
max_burst_jobs: int = -1,
@@ -218,14 +219,14 @@ def __init__(
218219
timezone: Optional[timezone] = None,
219220
log_results: bool = True,
220221
):
221-
self.functions: Dict[str, Union[Function, CronJob]] = {f.name: f for f in map(func, functions)}
222+
self.functions: dict[str, Union[Function, CronJob]] = {f.name: f for f in map(func, functions)}
222223
if queue_name is None:
223224
if redis_pool is not None:
224225
queue_name = redis_pool.default_queue_name
225226
else:
226227
raise ValueError('If queue_name is absent, redis_pool must be present.')
227228
self.queue_name = queue_name
228-
self.cron_jobs: List[CronJob] = []
229+
self.cron_jobs: list[CronJob] = []
229230
if cron_jobs is not None:
230231
if not all(isinstance(cj, CronJob) for cj in cron_jobs):
231232
raise RuntimeError('cron_jobs, must be instances of CronJob')
@@ -262,9 +263,9 @@ def __init__(
262263
else:
263264
self.redis_settings = None
264265
# self.tasks holds references to run_job coroutines currently running
265-
self.tasks: Dict[str, asyncio.Task[Any]] = {}
266+
self.tasks: dict[str, asyncio.Task[Any]] = {}
266267
# self.job_tasks holds references the actual jobs running
267-
self.job_tasks: Dict[str, asyncio.Task[Any]] = {}
268+
self.job_tasks: dict[str, asyncio.Task[Any]] = {}
268269
self.main_task: Optional[asyncio.Task[None]] = None
269270
self.loop = asyncio.get_event_loop()
270271
self.ctx = ctx or {}
@@ -289,7 +290,7 @@ def __init__(
289290
self.retry_jobs = retry_jobs
290291
self.allow_abort_jobs = allow_abort_jobs
291292
self.allow_pick_jobs: bool = True
292-
self.aborting_tasks: Set[str] = set()
293+
self.aborting_tasks: set[str] = set()
293294
self.max_burst_jobs = max_burst_jobs
294295
self.job_serializer = job_serializer
295296
self.job_deserializer = job_deserializer
@@ -409,7 +410,7 @@ async def _cancel_aborted_jobs(self) -> None:
409410
pipe.zremrangebyscore(abort_jobs_ss, min=timestamp_ms() + abort_job_max_age, max=float('inf'))
410411
abort_job_ids, _ = await pipe.execute()
411412

412-
aborted: Set[str] = set()
413+
aborted: set[str] = set()
413414
for job_id_bytes in abort_job_ids:
414415
job_id = job_id_bytes.decode()
415416
try:
@@ -428,7 +429,7 @@ def _release_sem_dec_counter_on_complete(self) -> None:
428429
self.job_counter = self.job_counter - 1
429430
self.sem.release()
430431

431-
async def start_jobs(self, job_ids: List[bytes]) -> None:
432+
async def start_jobs(self, job_ids: list[bytes]) -> None:
432433
"""
433434
For each job id, get the job definition, check it's not running and start it in a task
434435
"""
@@ -484,8 +485,8 @@ async def run_job(self, job_id: str, score: int) -> None: # noqa: C901
484485
abort_job = False
485486

486487
function_name, enqueue_time_ms = '<unknown>', 0
487-
args: Tuple[Any, ...] = ()
488-
kwargs: Dict[Any, Any] = {}
488+
args: tuple[Any, ...] = ()
489+
kwargs: dict[Any, Any] = {}
489490

490491
async def job_failed(exc: BaseException) -> None:
491492
self.jobs_failed += 1
@@ -879,7 +880,7 @@ def __repr__(self) -> str:
879880
)
880881

881882

882-
def get_kwargs(settings_cls: 'WorkerSettingsType') -> Dict[str, NameError]:
883+
def get_kwargs(settings_cls: 'WorkerSettingsType') -> dict[str, NameError]:
883884
worker_args = set(inspect.signature(Worker).parameters.keys())
884885
d = settings_cls if isinstance(settings_cls, dict) else settings_cls.__dict__
885886
return {k: v for k, v in d.items() if k in worker_args}

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import functools
33
import os
44
import sys
5-
from typing import Generator
5+
from collections.abc import Generator
66

77
import msgpack
88
import pytest

0 commit comments

Comments
 (0)