Skip to content

Commit 0b001e6

Browse files
committed
Step 2
1 parent 12c4184 commit 0b001e6

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
@@ -7,8 +7,6 @@
77
from functools import partialmethod
88
from functools import wraps
99
from typing import TYPE_CHECKING
10-
from typing import Any
11-
from typing import Callable
1210

1311
from django.apps import apps as django_apps
1412
from django.db import models
@@ -35,6 +33,13 @@
3533
]
3634

3735
if TYPE_CHECKING:
36+
from collections.abc import Callable
37+
from collections.abc import Sequence
38+
from typing import Any
39+
40+
from django.contrib.auth.models import AbstractBaseUser
41+
from django.utils.functional import _StrOrPromise
42+
3843
_Model = models.Model
3944
else:
4045
_Model = object
@@ -62,7 +67,16 @@ class ConcurrentTransition(Exception):
6267

6368

6469
class Transition:
65-
def __init__(self, method: Callable, source, target, on_error, conditions, permission, custom) -> None:
70+
def __init__(
71+
self,
72+
method: Callable,
73+
source: str | int | Sequence[str | int] | State,
74+
target: str | int | State | None,
75+
on_error: str | int | None,
76+
conditions: list[Callable[[Any], bool]],
77+
permission: str | Callable[[models.Model, AbstractBaseUser], bool] | None,
78+
custom: dict[str, _StrOrPromise],
79+
) -> None:
6680
self.method = method
6781
self.source = source
6882
self.target = target
@@ -493,7 +507,15 @@ def save(self, *args, **kwargs):
493507
self._update_initial_state()
494508

495509

496-
def transition(field, source="*", target=None, on_error=None, conditions=[], permission=None, custom={}):
510+
def transition(
511+
field,
512+
source: str | int | Sequence[str | int] | State = "*",
513+
target: str | int | State | None = None,
514+
on_error: str | int | None = None,
515+
conditions: list[Callable[[Any], bool]] = [],
516+
permission: str | Callable[[models.Model, AbstractBaseUser], bool] | None = None,
517+
custom: dict[str, _StrOrPromise] = {},
518+
):
497519
"""
498520
Method decorator to mark allowed transitions.
499521

0 commit comments

Comments
 (0)