Skip to content

Commit c4c2256

Browse files
committed
Only set slots on 3.11+
This works around an issue in `typing`'s handling of generics.
1 parent addb2cc commit c4c2256

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

django_tasks/backends/database/backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.core import checks
77
from django.core.exceptions import ValidationError
88
from django.db import transaction
9+
from django.utils.version import PY311
910
from typing_extensions import ParamSpec
1011

1112
from django_tasks.backends.base import BaseTaskBackend
@@ -21,7 +22,7 @@
2122
P = ParamSpec("P")
2223

2324

24-
@dataclass(frozen=True, slots=True, kw_only=True)
25+
@dataclass(frozen=True, slots=PY311, kw_only=True) # type: ignore[literal-required]
2526
class TaskResult(BaseTaskResult[T]):
2627
db_result: "DBTaskResult"
2728

django_tasks/base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from django.db.models.enums import TextChoices
1818
from django.utils.module_loading import import_string
1919
from django.utils.translation import pgettext_lazy
20+
from django.utils.version import PY311
2021
from typing_extensions import ParamSpec, Self
2122

2223
from .exceptions import TaskIntegrityError
@@ -64,7 +65,7 @@ class ResultStatus(TextChoices):
6465
P = ParamSpec("P")
6566

6667

67-
@dataclass(frozen=True, slots=True, kw_only=True)
68+
@dataclass(frozen=True, slots=PY311, kw_only=True) # type: ignore[literal-required]
6869
class Task(Generic[P, T]):
6970
priority: int
7071
"""The Task's priority"""
@@ -252,7 +253,7 @@ def wrapper(f: Callable[P, T]) -> Task[P, T]:
252253
return wrapper
253254

254255

255-
@dataclass(frozen=True, slots=True, kw_only=True)
256+
@dataclass(frozen=True, slots=PY311, kw_only=True) # type: ignore[literal-required]
256257
class TaskError:
257258
exception_class_path: str
258259
traceback: str
@@ -272,7 +273,7 @@ def exception_class(self) -> type[BaseException]:
272273
return exception_class
273274

274275

275-
@dataclass(frozen=True, slots=True, kw_only=True)
276+
@dataclass(frozen=True, slots=PY311, kw_only=True) # type: ignore[literal-required]
276277
class TaskResult(Generic[T]):
277278
task: Task
278279
"""Task for which this is a result"""
@@ -359,7 +360,7 @@ async def arefresh(self) -> None:
359360
object.__setattr__(self, attr, getattr(refreshed_task, attr))
360361

361362

362-
@dataclass(frozen=True, slots=True, kw_only=True)
363+
@dataclass(frozen=True, slots=PY311, kw_only=True) # type: ignore[literal-required]
363364
class TaskContext:
364365
task_result: TaskResult
365366

0 commit comments

Comments
 (0)