Skip to content

Commit 8a98c56

Browse files
committed
Step 2
1 parent 4445f72 commit 8a98c56

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

django_fsm/__init__.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from functools import partialmethod
99
from functools import wraps
1010
from typing import TYPE_CHECKING
11-
from typing import Any
12-
from typing import Callable
1311

1412
from django.apps import apps as django_apps
1513
from django.db import models
@@ -36,6 +34,13 @@
3634
]
3735

3836
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+
3944
_Model = models.Model
4045
else:
4146
_Model = object
@@ -63,7 +68,16 @@ class ConcurrentTransition(Exception):
6368

6469

6570
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:
6781
self.method = method
6882
self.source = source
6983
self.target = target
@@ -532,7 +546,15 @@ def save(self, *args, **kwargs):
532546
self._update_initial_state()
533547

534548

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+
):
536558
"""
537559
Method decorator to mark allowed transitions.
538560

0 commit comments

Comments
 (0)