Skip to content

Commit c7fcdc0

Browse files
committed
Step 2
1 parent 12c4184 commit c7fcdc0

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

django_fsm/__init__.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
from __future__ import annotations
55

66
import inspect
7+
from collections.abc import Callable
8+
from collections.abc import Sequence
79
from functools import partialmethod
810
from functools import wraps
911
from typing import TYPE_CHECKING
1012
from typing import Any
11-
from typing import Callable
1213

1314
from django.apps import apps as django_apps
1415
from django.db import models
@@ -35,6 +36,9 @@
3536
]
3637

3738
if TYPE_CHECKING:
39+
from django.contrib.auth.models import AbstractBaseUser
40+
from django.utils.functional import _StrOrPromise
41+
3842
_Model = models.Model
3943
else:
4044
_Model = object
@@ -62,7 +66,16 @@ class ConcurrentTransition(Exception):
6266

6367

6468
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:
6679
self.method = method
6780
self.source = source
6881
self.target = target
@@ -493,7 +506,15 @@ def save(self, *args, **kwargs):
493506
self._update_initial_state()
494507

495508

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+
):
497518
"""
498519
Method decorator to mark allowed transitions.
499520

0 commit comments

Comments
 (0)