1818from django_fsm .signals import pre_transition
1919
2020__all__ = [
21- "TransitionNotAllowed" ,
21+ "GET_STATE" ,
22+ "RETURN_VALUE" ,
2223 "ConcurrentTransition" ,
23- "FSMFieldMixin " ,
24+ "ConcurrentTransitionMixin " ,
2425 "FSMField" ,
26+ "FSMFieldMixin" ,
2527 "FSMIntegerField" ,
2628 "FSMKeyField" ,
27- "ConcurrentTransitionMixin" ,
28- "transition" ,
29+ "TransitionNotAllowed" ,
2930 "can_proceed" ,
3031 "has_transition_perm" ,
31- "GET_STATE" ,
32- "RETURN_VALUE" ,
32+ "transition" ,
3333]
3434
3535
36- class TransitionNotAllowed (Exception ):
36+ class TransitionNotAllowed (Exception ): # noqa: N818
3737 """Raised when a transition is not allowed"""
3838
3939 def __init__ (self , * args , ** kwargs ):
@@ -42,11 +42,11 @@ def __init__(self, *args, **kwargs):
4242 super ().__init__ (* args , ** kwargs )
4343
4444
45- class InvalidResultState (Exception ):
45+ class InvalidResultState (Exception ): # noqa: N818
4646 """Raised when we got invalid result state"""
4747
4848
49- class ConcurrentTransition (Exception ):
49+ class ConcurrentTransition (Exception ): # noqa: N818
5050 """
5151 Raised when the transition cannot be executed because the
5252 object has become stale (state has been changed since it
@@ -91,7 +91,7 @@ def __eq__(self, other):
9191 return False
9292
9393
94- def get_available_FIELD_transitions (instance , field ):
94+ def get_available_FIELD_transitions (instance , field ): # noqa: N802
9595 """
9696 List of transitions available in current model state
9797 with all conditions met
@@ -105,14 +105,14 @@ def get_available_FIELD_transitions(instance, field):
105105 yield meta .get_transition (curr_state )
106106
107107
108- def get_all_FIELD_transitions (instance , field ):
108+ def get_all_FIELD_transitions (instance , field ): # noqa: N802
109109 """
110110 List of all transitions available in current model state
111111 """
112112 return field .get_all_transitions (instance .__class__ )
113113
114114
115- def get_available_user_FIELD_transitions (instance , user , field ):
115+ def get_available_user_FIELD_transitions (instance , user , field ): # noqa: N802
116116 """
117117 List of transitions available in current model state
118118 with all conditions met and user have rights on it
@@ -211,7 +211,7 @@ class FSMFieldDescriptor:
211211 def __init__ (self , field ):
212212 self .field = field
213213
214- def __get__ (self , instance , type = None ):
214+ def __get__ (self , instance , instance_type = None ):
215215 if instance is None :
216216 return self
217217 return self .field .get_state (instance )
@@ -234,7 +234,7 @@ def __init__(self, *args, **kwargs):
234234 self .state_proxy = {} # state -> ProxyClsRef
235235
236236 state_choices = kwargs .pop ("state_choices" , None )
237- choices = kwargs .get ("choices" , None )
237+ choices = kwargs .get ("choices" )
238238 if state_choices is not None and choices is not None :
239239 raise ValueError ("Use one of choices or state_choices value" )
240240
@@ -344,8 +344,7 @@ def get_all_transitions(self, instance_cls):
344344 for transition in transitions .values ():
345345 meta = transition ._django_fsm
346346
347- for transition in meta .transitions .values ():
348- yield transition
347+ yield from meta .transitions .values ()
349348
350349 def contribute_to_class (self , cls , name , ** kwargs ):
351350 self .base_cls = cls
@@ -406,8 +405,6 @@ class FSMIntegerField(FSMFieldMixin, models.IntegerField):
406405 Same as FSMField, but stores the state value in an IntegerField.
407406 """
408407
409- pass
410-
411408
412409class FSMKeyField (FSMFieldMixin , models .ForeignKey ):
413410 """
@@ -557,7 +554,7 @@ def _change_state(instance, *args, **kwargs):
557554 return inner_transition
558555
559556
560- def can_proceed (bound_method , check_conditions = True ):
557+ def can_proceed (bound_method , check_conditions = True ): # noqa: FBT002
561558 """
562559 Returns True if model in state allows to call bound_method
563560
@@ -597,25 +594,23 @@ def get_state(self, model, transition, result, args=[], kwargs={}):
597594 raise NotImplementedError
598595
599596
600- class RETURN_VALUE (State ):
597+ class RETURN_VALUE (State ): # noqa: N801
601598 def __init__ (self , * allowed_states ):
602599 self .allowed_states = allowed_states if allowed_states else None
603600
604601 def get_state (self , model , transition , result , args = [], kwargs = {}):
605- if self .allowed_states is not None :
606- if result not in self .allowed_states :
607- raise InvalidResultState (f"{ result } is not in list of allowed states\n { self .allowed_states } " )
602+ if self .allowed_states is not None and result not in self .allowed_states :
603+ raise InvalidResultState (f"{ result } is not in list of allowed states\n { self .allowed_states } " )
608604 return result
609605
610606
611- class GET_STATE (State ):
607+ class GET_STATE (State ): # noqa: N801
612608 def __init__ (self , func , states = None ):
613609 self .func = func
614610 self .allowed_states = states
615611
616612 def get_state (self , model , transition , result , args = [], kwargs = {}):
617613 result_state = self .func (model , * args , ** kwargs )
618- if self .allowed_states is not None :
619- if result_state not in self .allowed_states :
620- raise InvalidResultState (f"{ result_state } is not in list of allowed states\n { self .allowed_states } " )
614+ if self .allowed_states is not None and result_state not in self .allowed_states :
615+ raise InvalidResultState (f"{ result_state } is not in list of allowed states\n { self .allowed_states } " )
621616 return result_state
0 commit comments