Skip to content

Commit

Permalink
Revert "Drop support for Python 3.8"
Browse files Browse the repository at this point in the history
It's needed to maintain support for older Django versions.

This reverts commit 8073900 and f970f5b.
  • Loading branch information
RealOrangeOne committed Feb 3, 2025
1 parent 4edc550 commit 2de5902
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 26 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ jobs:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
django-version: ["4.2", "5.0", "5.1"]
exclude:
- django-version: "5.0"
python-version: "3.8"
- django-version: "5.0"
python-version: "3.9"
- django-version: "5.1"
python-version: "3.8"
- django-version: "5.1"
python-version: "3.9"
- os: windows-latest # JSON1 is only built-in on 3.9+
python-version: 3.8

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 1 addition & 2 deletions django_tasks/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from abc import ABCMeta, abstractmethod
from collections.abc import Iterable
from inspect import iscoroutinefunction
from typing import Any, TypeVar
from typing import Any, Iterable, TypeVar

from asgiref.sync import sync_to_async
from django.core.checks import messages
Expand Down
4 changes: 2 additions & 2 deletions django_tasks/backends/database/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import List, Optional

from django.contrib import admin
from django.http import HttpRequest
Expand Down Expand Up @@ -38,5 +38,5 @@ def has_change_permission(

def get_readonly_fields(
self, request: HttpRequest, obj: Optional[DBTaskResult] = None
) -> list[str]:
) -> List[str]:
return [f.name for f in self.model._meta.fields]
3 changes: 1 addition & 2 deletions django_tasks/backends/database/backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections.abc import Iterable
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, TypeVar
from typing import TYPE_CHECKING, Any, Iterable, TypeVar

import django
from django.apps import apps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
from argparse import ArgumentParser, ArgumentTypeError
from types import FrameType
from typing import Optional
from typing import List, Optional

from django.core.exceptions import SuspiciousOperation
from django.core.management.base import BaseCommand
Expand All @@ -29,7 +29,7 @@ class Worker:
def __init__(
self,
*,
queue_names: list[str],
queue_names: List[str],
interval: float,
batch: bool,
backend_name: str,
Expand Down
3 changes: 1 addition & 2 deletions django_tasks/backends/database/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections.abc import Generator
from contextlib import contextmanager
from typing import Any, Optional, Union
from typing import Any, Generator, Optional, Union
from uuid import UUID

import django
Expand Down
4 changes: 2 additions & 2 deletions django_tasks/backends/dummy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from copy import deepcopy
from functools import partial
from typing import TypeVar
from typing import List, TypeVar

from django.db import transaction
from django.utils import timezone
Expand All @@ -20,7 +20,7 @@
class DummyBackend(BaseTaskBackend):
supports_defer = True
supports_async_task = True
results: list[TaskResult]
results: List[TaskResult]

def __init__(self, alias: str, params: dict) -> None:
super().__init__(alias, params)
Expand Down
3 changes: 1 addition & 2 deletions django_tasks/checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections.abc import Iterable, Sequence
from typing import Any
from typing import Any, Iterable, Sequence

from django.apps.config import AppConfig
from django.core.checks.messages import CheckMessage
Expand Down
5 changes: 3 additions & 2 deletions django_tasks/signal_handlers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Type

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

@receiver(task_enqueued)
def log_task_enqueued(
sender: type[BaseTaskBackend], task_result: TaskResult, **kwargs: dict
sender: Type[BaseTaskBackend], task_result: TaskResult, **kwargs: dict
) -> None:
logger.debug(
"Task id=%s path=%s enqueued backend=%s",
Expand All @@ -37,7 +38,7 @@ def log_task_enqueued(

@receiver(task_finished)
def log_task_finished(
sender: type[BaseTaskBackend], task_result: TaskResult, **kwargs: dict
sender: Type[BaseTaskBackend], task_result: TaskResult, **kwargs: dict
) -> None:
if task_result.status == ResultStatus.FAILED:
# Use `.exception` to integrate with error monitoring tools (eg Sentry)
Expand Down
10 changes: 6 additions & 4 deletions django_tasks/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
TYPE_CHECKING,
Any,
Callable,
Dict,
Generic,
Optional,
Type,
TypeVar,
Union,
cast,
Expand Down Expand Up @@ -100,7 +102,7 @@ def using(
Create a new task with modified defaults
"""

changes: dict[str, Any] = {}
changes: Dict[str, Any] = {}

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

kwargs: dict[str, Any]
kwargs: Dict[str, Any]
"""The keyword arguments to pass to the task function"""

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

_exception_class: Optional[type[BaseException]] = field(init=False, default=None)
_exception_class: Optional[Type[BaseException]] = field(init=False, default=None)
_traceback: Optional[str] = field(init=False, default=None)

_return_value: Optional[T] = field(init=False, default=None)
Expand All @@ -270,7 +272,7 @@ def return_value(self) -> Optional[T]:
raise ValueError("Task has not finished yet")

@property
def exception_class(self) -> Optional[type[BaseException]]:
def exception_class(self) -> Optional[Type[BaseException]]:
"""The exception raised by the task function"""
if not self.is_finished:
raise ValueError("Task has not finished yet")
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -35,7 +36,7 @@ classifiers = [
"Topic :: Internet :: WWW/HTTP",
"Typing :: Typed"
]
requires-python = ">=3.9"
requires-python = ">=3.8"
dependencies = [
"Django>=4.2",
"typing_extensions",
Expand Down
7 changes: 3 additions & 4 deletions tests/tests/test_immediate_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ def test_catches_exception(self) -> None:
),
]
for task, exception, message in test_data:
with (
self.subTest(task),
self.assertLogs("django_tasks", level="ERROR") as captured_logs,
):
with self.subTest(task), self.assertLogs(
"django_tasks", level="ERROR"
) as captured_logs:
result = task.enqueue()

# assert logging
Expand Down

0 comments on commit 2de5902

Please sign in to comment.