Skip to content

Commit f970f5b

Browse files
committed
Upgrade syntax for Python 3.9+
1 parent 8073900 commit f970f5b

File tree

10 files changed

+24
-22
lines changed

10 files changed

+24
-22
lines changed

django_tasks/backends/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from abc import ABCMeta, abstractmethod
2+
from collections.abc import Iterable
23
from inspect import iscoroutinefunction
3-
from typing import Any, Iterable, TypeVar
4+
from typing import Any, TypeVar
45

56
from asgiref.sync import sync_to_async
67
from django.core.checks import messages

django_tasks/backends/database/admin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional
1+
from typing import Optional
22

33
from django.contrib import admin
44
from django.http import HttpRequest
@@ -38,5 +38,5 @@ def has_change_permission(
3838

3939
def get_readonly_fields(
4040
self, request: HttpRequest, obj: Optional[DBTaskResult] = None
41-
) -> List[str]:
41+
) -> list[str]:
4242
return [f.name for f in self.model._meta.fields]

django_tasks/backends/database/backend.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from collections.abc import Iterable
12
from dataclasses import dataclass
2-
from typing import TYPE_CHECKING, Any, Iterable, TypeVar
3+
from typing import TYPE_CHECKING, Any, TypeVar
34

45
import django
56
from django.apps import apps

django_tasks/backends/database/management/commands/db_worker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
from argparse import ArgumentParser, ArgumentTypeError
88
from types import FrameType
9-
from typing import List, Optional
9+
from typing import Optional
1010

1111
from django.core.exceptions import SuspiciousOperation
1212
from django.core.management.base import BaseCommand
@@ -29,7 +29,7 @@ class Worker:
2929
def __init__(
3030
self,
3131
*,
32-
queue_names: List[str],
32+
queue_names: list[str],
3333
interval: float,
3434
batch: bool,
3535
backend_name: str,

django_tasks/backends/database/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from collections.abc import Generator
12
from contextlib import contextmanager
2-
from typing import Any, Generator, Optional, Union
3+
from typing import Any, Optional, Union
34
from uuid import UUID
45

56
import django

django_tasks/backends/dummy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from copy import deepcopy
22
from functools import partial
3-
from typing import List, TypeVar
3+
from typing import TypeVar
44

55
from django.db import transaction
66
from django.utils import timezone
@@ -20,7 +20,7 @@
2020
class DummyBackend(BaseTaskBackend):
2121
supports_defer = True
2222
supports_async_task = True
23-
results: List[TaskResult]
23+
results: list[TaskResult]
2424

2525
def __init__(self, alias: str, params: dict) -> None:
2626
super().__init__(alias, params)

django_tasks/checks.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Iterable, Sequence
1+
from collections.abc import Iterable, Sequence
2+
from typing import Any
23

34
from django.apps.config import AppConfig
45
from django.core.checks.messages import CheckMessage

django_tasks/signal_handlers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from typing import Type
32

43
from asgiref.local import Local
54
from django.core.signals import setting_changed
@@ -26,7 +25,7 @@ def clear_tasks_handlers(*, setting: str, **kwargs: dict) -> None:
2625

2726
@receiver(task_enqueued)
2827
def log_task_enqueued(
29-
sender: Type[BaseTaskBackend], task_result: TaskResult, **kwargs: dict
28+
sender: type[BaseTaskBackend], task_result: TaskResult, **kwargs: dict
3029
) -> None:
3130
logger.debug(
3231
"Task id=%s path=%s enqueued backend=%s",
@@ -38,7 +37,7 @@ def log_task_enqueued(
3837

3938
@receiver(task_finished)
4039
def log_task_finished(
41-
sender: Type[BaseTaskBackend], task_result: TaskResult, **kwargs: dict
40+
sender: type[BaseTaskBackend], task_result: TaskResult, **kwargs: dict
4241
) -> None:
4342
if task_result.status == ResultStatus.FAILED:
4443
# Use `.exception` to integrate with error monitoring tools (eg Sentry)

django_tasks/task.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
TYPE_CHECKING,
66
Any,
77
Callable,
8-
Dict,
98
Generic,
109
Optional,
11-
Type,
1210
TypeVar,
1311
Union,
1412
cast,
@@ -102,7 +100,7 @@ def using(
102100
Create a new task with modified defaults
103101
"""
104102

105-
changes: Dict[str, Any] = {}
103+
changes: dict[str, Any] = {}
106104

107105
if priority is not None:
108106
changes["priority"] = priority
@@ -245,13 +243,13 @@ class TaskResult(Generic[T]):
245243
args: list
246244
"""The arguments to pass to the task function"""
247245

248-
kwargs: Dict[str, Any]
246+
kwargs: dict[str, Any]
249247
"""The keyword arguments to pass to the task function"""
250248

251249
backend: str
252250
"""The name of the backend the task will run on"""
253251

254-
_exception_class: Optional[Type[BaseException]] = field(init=False, default=None)
252+
_exception_class: Optional[type[BaseException]] = field(init=False, default=None)
255253
_traceback: Optional[str] = field(init=False, default=None)
256254

257255
_return_value: Optional[T] = field(init=False, default=None)
@@ -270,7 +268,7 @@ def return_value(self) -> Optional[T]:
270268
return cast(T, self._return_value)
271269

272270
@property
273-
def exception_class(self) -> Optional[Type[BaseException]]:
271+
def exception_class(self) -> Optional[type[BaseException]]:
274272
"""The exception raised by the task function"""
275273
if not self.is_finished:
276274
raise ValueError("Task has not finished yet")

tests/tests/test_immediate_backend.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ def test_catches_exception(self) -> None:
7171
),
7272
]
7373
for task, exception, message in test_data:
74-
with self.subTest(task), self.assertLogs(
75-
"django_tasks", level="ERROR"
76-
) as captured_logs:
74+
with (
75+
self.subTest(task),
76+
self.assertLogs("django_tasks", level="ERROR") as captured_logs,
77+
):
7778
result = task.enqueue()
7879

7980
# assert logging

0 commit comments

Comments
 (0)