5
5
from __future__ import annotations
6
6
7
7
import inspect
8
- from collections .abc import Callable
9
- from collections .abc import Collection
10
- from collections .abc import Generator
11
- from collections .abc import Iterable
12
- from collections .abc import Sequence
13
8
from functools import partialmethod
14
9
from functools import wraps
15
10
from typing import TYPE_CHECKING
41
36
]
42
37
43
38
if TYPE_CHECKING :
39
+ from collections .abc import Callable
40
+ from collections .abc import Collection
41
+ from collections .abc import Generator
42
+ from collections .abc import Iterable
43
+ from collections .abc import Sequence
44
44
from typing import Self
45
45
46
46
from _typeshed import Incomplete
@@ -121,10 +121,10 @@ def has_perm(self, instance: _Instance, user: UserWithPermissions) -> bool:
121
121
return True
122
122
return False
123
123
124
- def __hash__ (self ):
124
+ def __hash__ (self ) -> int :
125
125
return hash (self .name )
126
126
127
- def __eq__ (self , other ) :
127
+ def __eq__ (self , other : object ) -> bool :
128
128
if isinstance (other , str ):
129
129
return other == self .name
130
130
if isinstance (other , Transition ):
@@ -240,8 +240,8 @@ def has_transition_perm(self, instance: _Instance, state: str, user: UserWithPer
240
240
241
241
if not transition :
242
242
return False
243
- else :
244
- return bool (transition .has_perm (instance , user ))
243
+
244
+ return bool (transition .has_perm (instance , user ))
245
245
246
246
def next_state (self , current_state : str ) -> _StateValue :
247
247
transition = self .get_transition (current_state )
@@ -309,7 +309,7 @@ def deconstruct(self) -> Any:
309
309
def get_state (self , instance : _Instance ) -> Any :
310
310
# The state field may be deferred. We delegate the logic of figuring this out
311
311
# and loading the deferred field on-demand to Django's built-in DeferredAttribute class.
312
- return DeferredAttribute (self ).__get__ (instance ) # type: ignore[attr-defined]
312
+ return DeferredAttribute (self ).__get__ (instance )
313
313
314
314
def set_state (self , instance : _Instance , state : str ) -> None :
315
315
instance .__dict__ [self .name ] = state
@@ -479,14 +479,14 @@ class FSMModelMixin(_FSMModel):
479
479
Mixin that allows refresh_from_db for models with fsm protected fields
480
480
"""
481
481
482
- def _get_protected_fsm_fields (self ):
483
- def is_fsm_and_protected (f ) :
482
+ def _get_protected_fsm_fields (self ) -> set [ str ] :
483
+ def is_fsm_and_protected (f : object ) -> Any :
484
484
return isinstance (f , FSMFieldMixin ) and f .protected
485
485
486
- protected_fields = filter (is_fsm_and_protected , self ._meta .concrete_fields )
486
+ protected_fields : Iterable [ Any ] = filter (is_fsm_and_protected , self ._meta .concrete_fields ) # type: ignore[attr-defined, arg-type]
487
487
return {f .attname for f in protected_fields }
488
488
489
- def refresh_from_db (self , * args , ** kwargs ) :
489
+ def refresh_from_db (self , * args : Any , ** kwargs : Any ) -> None :
490
490
fields = kwargs .pop ("fields" , None )
491
491
492
492
# Use provided fields, if not set then reload all non-deferred fields.0
@@ -495,7 +495,7 @@ def refresh_from_db(self, *args, **kwargs):
495
495
protected_fields = self ._get_protected_fsm_fields ()
496
496
skipped_fields = deferred_fields .union (protected_fields )
497
497
498
- fields = [f .attname for f in self ._meta .concrete_fields if f .attname not in skipped_fields ]
498
+ fields = [f .attname for f in self ._meta .concrete_fields if f .attname not in skipped_fields ] # type: ignore[attr-defined]
499
499
500
500
kwargs ["fields" ] = fields
501
501
super ().refresh_from_db (* args , ** kwargs )
@@ -538,9 +538,9 @@ def state_fields(self) -> Iterable[Any]:
538
538
def _do_update (
539
539
self ,
540
540
base_qs : QuerySet [Self ],
541
- using : Any ,
541
+ using : str | None ,
542
542
pk_val : Any ,
543
- values : Collection [Any ] | None ,
543
+ values : Collection [tuple [ _Field , type [ models . Model ] | None , Any ]] ,
544
544
update_fields : Iterable [str ] | None ,
545
545
forced_update : bool ,
546
546
) -> bool :
@@ -553,7 +553,7 @@ def _do_update(
553
553
# state filter will be used to narrow down the standard filter checking only PK
554
554
state_filter = {field .attname : self .__initial_states [field .attname ] for field in filter_on }
555
555
556
- updated : bool = super ()._do_update ( # type: ignore[misc]
556
+ updated : bool = super ()._do_update (
557
557
base_qs = base_qs .filter (** state_filter ),
558
558
using = using ,
559
559
pk_val = pk_val ,
0 commit comments