2121from django_fsm .signals import pre_transition
2222
2323if typing .TYPE_CHECKING : # pragma: no cover
24- from collections .abc import Callable
25- from collections .abc import Collection
26- from collections .abc import Generator
27- from collections .abc import Iterable
28- from collections .abc import Sequence
2924 from typing import Self
3025
3126 from django .contrib .auth .models import AbstractUser
3934 IntegerField : typing .TypeAlias = models .IntegerField [int , int ]
4035 ForeignKey : typing .TypeAlias = models .ForeignKey [typing .Any , typing .Any ]
4136
42- _FSMModel = models .Model
37+ _FSMModel : typing . TypeAlias = models .Model
4338 _StateValue : typing .TypeAlias = str | int | models .Choices
44- _Permission : typing .TypeAlias = str | Callable [[_FSMModel , typing .Any ], bool ]
45- _Condition : typing .TypeAlias = Callable [[models .Model ], bool ]
39+ _Permission : typing .TypeAlias = str | typing .Callable [[_FSMModel , UserWithPermissions ], bool ]
40+ _Condition : typing .TypeAlias = typing .Callable [[_FSMModel ], bool ]
41+ _TransitionFunc : typing .TypeAlias = typing .Callable [..., _StateValue | typing .Any | None ]
4642
4743else :
4844 _FSMModel = object
@@ -99,7 +95,7 @@ class ConcurrentTransition(Exception): # noqa: N818
9995class Transition :
10096 def __init__ (
10197 self ,
102- method : Callable [..., _StateValue | None ] ,
98+ method : _TransitionFunc ,
10399 source : _StateValue ,
104100 target : _StateValue ,
105101 on_error : _StateValue | None ,
@@ -147,7 +143,7 @@ def __eq__(self, other: object) -> bool:
147143
148144def get_available_FIELD_transitions ( # noqa: N802
149145 instance : _FSMModel , field : FSMFieldMixin
150- ) -> Generator [Transition ]:
146+ ) -> typing . Generator [Transition ]:
151147 """
152148 List of transitions available in current model state
153149 with all conditions met
@@ -161,7 +157,9 @@ def get_available_FIELD_transitions( # noqa: N802
161157 yield meta .get_transition (curr_state )
162158
163159
164- def get_all_FIELD_transitions (instance : _FSMModel , field : FSMFieldMixin ) -> Generator [Transition ]: # noqa: N802
160+ def get_all_FIELD_transitions ( # noqa: N802
161+ instance : _FSMModel , field : FSMFieldMixin
162+ ) -> typing .Generator [Transition ]:
165163 """
166164 List of all transitions available in current model state
167165 """
@@ -170,7 +168,7 @@ def get_all_FIELD_transitions(instance: _FSMModel, field: FSMFieldMixin) -> Gene
170168
171169def get_available_user_FIELD_transitions ( # noqa: N802
172170 instance : _FSMModel , user : UserWithPermissions , field : FSMFieldMixin
173- ) -> Generator [Transition ]:
171+ ) -> typing . Generator [Transition ]:
174172 """
175173 List of transitions available in current model state
176174 with all conditions met and user have rights on it
@@ -199,12 +197,12 @@ def get_transition(self, source: _StateValue) -> Transition | None:
199197
200198 def add_transition (
201199 self ,
202- method : Callable [..., _StateValue ] ,
200+ method : _TransitionFunc ,
203201 source : _StateValue ,
204202 target : _StateValue ,
205203 on_error : _StateValue | None = None ,
206204 conditions : list [_Condition ] | None = None ,
207- permission : str | Callable [[ _FSMModel , UserWithPermissions ], bool ] | None = None ,
205+ permission : _Permission | None = None ,
208206 custom : dict [str , typing .Any ] | None = None ,
209207 ) -> None :
210208 if source in self .transitions :
@@ -320,7 +318,7 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
320318 super ().__init__ (* args , ** kwargs )
321319
322320 @override
323- def deconstruct (self ) -> tuple [str , str , Sequence [typing .Any ], dict [str , typing .Any ]]:
321+ def deconstruct (self ) -> tuple [str , str , typing . Sequence [typing .Any ], dict [str , typing .Any ]]:
324322 name , path , args , kwargs = super ().deconstruct ()
325323 if self .protected :
326324 kwargs ["protected" ] = self .protected
@@ -414,7 +412,7 @@ def change_state(
414412
415413 return result
416414
417- def get_all_transitions (self , instance_cls : type [_FSMModel ]) -> Generator [Transition ]:
415+ def get_all_transitions (self , instance_cls : type [_FSMModel ]) -> typing . Generator [Transition ]:
418416 """
419417 Returns [(source, target, name, method)] for all field transitions
420418 """
@@ -458,7 +456,7 @@ def _collect_transitions(self, *args: typing.Any, **kwargs: typing.Any) -> None:
458456 if not issubclass (sender , self .base_cls ):
459457 return
460458
461- def is_field_transition_method (attr : Callable [[ typing . Any ], typing . Any ] ) -> bool :
459+ def is_field_transition_method (attr : _TransitionFunc ) -> bool :
462460 return (
463461 (inspect .ismethod (attr ) or inspect .isfunction (attr ))
464462 and hasattr (attr , "_django_fsm" )
@@ -567,7 +565,7 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
567565 self ._update_initial_state ()
568566
569567 @property
570- def state_fields (self ) -> Iterable [FSMFieldMixin ]:
568+ def state_fields (self ) -> typing . Iterable [FSMFieldMixin ]:
571569 return filter (lambda field : isinstance (field , FSMFieldMixin ), self ._meta .fields ) # type: ignore[arg-type]
572570
573571 @override
@@ -576,8 +574,8 @@ def _do_update(
576574 base_qs : QuerySet [Self ],
577575 using : str | None ,
578576 pk_val : typing .Any ,
579- values : Collection [tuple [_Field , type [models .Model ] | None , typing .Any ]],
580- update_fields : Iterable [str ] | None ,
577+ values : typing . Collection [tuple [_Field , type [models .Model ] | None , typing .Any ]],
578+ update_fields : typing . Iterable [str ] | None ,
581579 forced_update : bool ,
582580 returning_fields : bool | None = None ,
583581 ) -> bool :
@@ -644,13 +642,13 @@ def save(self, *args: typing.Any, **kwargs: typing.Any) -> None:
644642
645643def transition (
646644 field : FSMFieldMixin | str ,
647- source : _StateValue | Sequence [_StateValue ] = "*" ,
645+ source : _StateValue | typing . Sequence [_StateValue ] = "*" ,
648646 target : _StateValue | State | None = None ,
649647 on_error : _StateValue | None = None ,
650648 conditions : list [_Condition ] | None = None ,
651649 permission : _Permission | None = None ,
652650 custom : dict [str , typing .Any ] | None = None ,
653- ) -> Callable [[typing .Any ], typing .Any ]:
651+ ) -> typing . Callable [[typing .Any ], typing .Any ]:
654652 """
655653 Method decorator to mark allowed transitions.
656654
@@ -728,14 +726,14 @@ def has_transition_perm(bound_method: typing.Any, user: UserWithPermissions) ->
728726
729727
730728class State :
731- allowed_states : Sequence [_StateValue ]
729+ allowed_states : typing . Sequence [_StateValue ]
732730
733731 def get_state (
734732 self ,
735733 model : _FSMModel ,
736734 transition : Transition ,
737735 result : typing .Any ,
738- args : Sequence [typing .Any ] | None = None ,
736+ args : typing . Sequence [typing .Any ] | None = None ,
739737 kwargs : dict [str , typing .Any ] | None = None ,
740738 ) -> typing .Any :
741739 raise NotImplementedError
@@ -750,7 +748,7 @@ def get_state(
750748 model : _FSMModel ,
751749 transition : Transition ,
752750 result : typing .Any ,
753- args : Sequence [typing .Any ] | None = None ,
751+ args : typing . Sequence [typing .Any ] | None = None ,
754752 kwargs : dict [str , typing .Any ] | None = None ,
755753 ) -> typing .Any :
756754 if self .allowed_states is not None and result not in self .allowed_states :
@@ -763,8 +761,8 @@ def get_state(
763761class GET_STATE (State ): # noqa: N801
764762 def __init__ (
765763 self ,
766- func : Callable [..., _StateValue ],
767- states : Sequence [_StateValue ] | None = None ,
764+ func : typing . Callable [..., _StateValue ],
765+ states : typing . Sequence [_StateValue ] | None = None ,
768766 ) -> None :
769767 self .func = func
770768 self .allowed_states = states or []
@@ -774,7 +772,7 @@ def get_state(
774772 model : _FSMModel ,
775773 transition : Transition ,
776774 result : _StateValue ,
777- args : Sequence [typing .Any ] | None = None ,
775+ args : typing . Sequence [typing .Any ] | None = None ,
778776 kwargs : dict [str , typing .Any ] | None = None ,
779777 ) -> typing .Any :
780778 if args is None :
0 commit comments