|
4 | 4 | from __future__ import annotations |
5 | 5 |
|
6 | 6 | import inspect |
| 7 | +from collections.abc import Callable |
| 8 | +from collections.abc import Sequence |
7 | 9 | from functools import partialmethod |
8 | 10 | from functools import wraps |
9 | 11 | from typing import TYPE_CHECKING |
10 | 12 | from typing import Any |
11 | | -from typing import Callable |
12 | 13 |
|
13 | 14 | from django.apps import apps as django_apps |
14 | 15 | from django.db import models |
|
35 | 36 | ] |
36 | 37 |
|
37 | 38 | if TYPE_CHECKING: |
| 39 | + from django.contrib.auth.models import AbstractBaseUser |
| 40 | + from django.utils.functional import _StrOrPromise |
| 41 | + |
38 | 42 | _Model = models.Model |
39 | 43 | else: |
40 | 44 | _Model = object |
@@ -62,7 +66,16 @@ class ConcurrentTransition(Exception): |
62 | 66 |
|
63 | 67 |
|
64 | 68 | class Transition: |
65 | | - def __init__(self, method: Callable, source, target, on_error, conditions, permission, custom) -> None: |
| 69 | + def __init__( |
| 70 | + self, |
| 71 | + method: Callable, |
| 72 | + source: str | int | Sequence[str | int] | State, |
| 73 | + target: str | int | State | None, |
| 74 | + on_error: str | int | None, |
| 75 | + conditions: list[Callable[[Any], bool]], |
| 76 | + permission: str | Callable[[models.Model, AbstractBaseUser], bool] | None, |
| 77 | + custom: dict[str, _StrOrPromise], |
| 78 | + ) -> None: |
66 | 79 | self.method = method |
67 | 80 | self.source = source |
68 | 81 | self.target = target |
@@ -493,7 +506,15 @@ def save(self, *args, **kwargs): |
493 | 506 | self._update_initial_state() |
494 | 507 |
|
495 | 508 |
|
496 | | -def transition(field, source="*", target=None, on_error=None, conditions=[], permission=None, custom={}): |
| 509 | +def transition( |
| 510 | + field, |
| 511 | + source: str | int | Sequence[str | int] | State = "*", |
| 512 | + target: str | int | State | None = None, |
| 513 | + on_error: str | int | None = None, |
| 514 | + conditions: list[Callable[[Any], bool]] = [], |
| 515 | + permission: str | Callable[[models.Model, AbstractBaseUser], bool] | None = None, |
| 516 | + custom: dict[str, _StrOrPromise] = {}, |
| 517 | +): |
497 | 518 | """ |
498 | 519 | Method decorator to mark allowed transitions. |
499 | 520 |
|
|
0 commit comments