|
8 | 8 | from functools import partialmethod
|
9 | 9 | from functools import wraps
|
10 | 10 | from typing import TYPE_CHECKING
|
11 |
| -from typing import Any |
12 |
| -from typing import Callable |
13 | 11 |
|
14 | 12 | from django.apps import apps as django_apps
|
15 | 13 | from django.db import models
|
|
36 | 34 | ]
|
37 | 35 |
|
38 | 36 | if TYPE_CHECKING:
|
| 37 | + from collections.abc import Callable |
| 38 | + from collections.abc import Sequence |
| 39 | + from typing import Any |
| 40 | + |
| 41 | + from django.contrib.auth.models import AbstractBaseUser |
| 42 | + from django.utils.functional import _StrOrPromise |
| 43 | + |
39 | 44 | _Model = models.Model
|
40 | 45 | else:
|
41 | 46 | _Model = object
|
@@ -63,7 +68,16 @@ class ConcurrentTransition(Exception):
|
63 | 68 |
|
64 | 69 |
|
65 | 70 | class Transition:
|
66 |
| - def __init__(self, method: Callable, source, target, on_error, conditions, permission, custom) -> None: |
| 71 | + def __init__( |
| 72 | + self, |
| 73 | + method: Callable, |
| 74 | + source: str | int | Sequence[str | int] | State, |
| 75 | + target: str | int | State | None, |
| 76 | + on_error: str | int | None, |
| 77 | + conditions: list[Callable[[Any], bool]], |
| 78 | + permission: str | Callable[[models.Model, AbstractBaseUser], bool] | None, |
| 79 | + custom: dict[str, _StrOrPromise], |
| 80 | + ) -> None: |
67 | 81 | self.method = method
|
68 | 82 | self.source = source
|
69 | 83 | self.target = target
|
@@ -532,7 +546,15 @@ def save(self, *args, **kwargs):
|
532 | 546 | self._update_initial_state()
|
533 | 547 |
|
534 | 548 |
|
535 |
| -def transition(field, source="*", target=None, on_error=None, conditions=[], permission=None, custom={}): |
| 549 | +def transition( |
| 550 | + field, |
| 551 | + source: str | int | Sequence[str | int] | State = "*", |
| 552 | + target: str | int | State | None = None, |
| 553 | + on_error: str | int | None = None, |
| 554 | + conditions: list[Callable[[Any], bool]] = [], |
| 555 | + permission: str | Callable[[models.Model, AbstractBaseUser], bool] | None = None, |
| 556 | + custom: dict[str, _StrOrPromise] = {}, |
| 557 | +): |
536 | 558 | """
|
537 | 559 | Method decorator to mark allowed transitions.
|
538 | 560 |
|
|
0 commit comments