Skip to content

Commit 3f506d5

Browse files
committed
Step 8
1 parent ec9184b commit 3f506d5

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ repos:
5050
- id: ruff
5151

5252
- repo: https://github.com/pre-commit/mirrors-mypy
53-
rev: v1.7.1
53+
rev: v1.10.0
5454
hooks:
5555
- id: mypy
5656
additional_dependencies:
57-
- django-stubs==4.2.6
57+
- django-stubs==5.0.0
5858
- django-guardian

django_fsm/__init__.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
from __future__ import annotations
66

77
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
138
from functools import partialmethod
149
from functools import wraps
1510
from typing import TYPE_CHECKING
@@ -41,6 +36,11 @@
4136
]
4237

4338
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
4444
from typing import Self
4545

4646
from _typeshed import Incomplete
@@ -121,10 +121,10 @@ def has_perm(self, instance: _Instance, user: UserWithPermissions) -> bool:
121121
return True
122122
return False
123123

124-
def __hash__(self):
124+
def __hash__(self) -> int:
125125
return hash(self.name)
126126

127-
def __eq__(self, other):
127+
def __eq__(self, other: object) -> bool:
128128
if isinstance(other, str):
129129
return other == self.name
130130
if isinstance(other, Transition):
@@ -240,8 +240,8 @@ def has_transition_perm(self, instance: _Instance, state: str, user: UserWithPer
240240

241241
if not transition:
242242
return False
243-
else:
244-
return bool(transition.has_perm(instance, user))
243+
244+
return bool(transition.has_perm(instance, user))
245245

246246
def next_state(self, current_state: str) -> _StateValue:
247247
transition = self.get_transition(current_state)
@@ -309,7 +309,7 @@ def deconstruct(self) -> Any:
309309
def get_state(self, instance: _Instance) -> Any:
310310
# The state field may be deferred. We delegate the logic of figuring this out
311311
# 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)
313313

314314
def set_state(self, instance: _Instance, state: str) -> None:
315315
instance.__dict__[self.name] = state
@@ -479,14 +479,14 @@ class FSMModelMixin(_FSMModel):
479479
Mixin that allows refresh_from_db for models with fsm protected fields
480480
"""
481481

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:
484484
return isinstance(f, FSMFieldMixin) and f.protected
485485

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]
487487
return {f.attname for f in protected_fields}
488488

489-
def refresh_from_db(self, *args, **kwargs):
489+
def refresh_from_db(self, *args: Any, **kwargs: Any) -> None:
490490
fields = kwargs.pop("fields", None)
491491

492492
# Use provided fields, if not set then reload all non-deferred fields.0
@@ -495,7 +495,7 @@ def refresh_from_db(self, *args, **kwargs):
495495
protected_fields = self._get_protected_fsm_fields()
496496
skipped_fields = deferred_fields.union(protected_fields)
497497

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]
499499

500500
kwargs["fields"] = fields
501501
super().refresh_from_db(*args, **kwargs)
@@ -538,9 +538,9 @@ def state_fields(self) -> Iterable[Any]:
538538
def _do_update(
539539
self,
540540
base_qs: QuerySet[Self],
541-
using: Any,
541+
using: str | None,
542542
pk_val: Any,
543-
values: Collection[Any] | None,
543+
values: Collection[tuple[_Field, type[models.Model] | None, Any]],
544544
update_fields: Iterable[str] | None,
545545
forced_update: bool,
546546
) -> bool:
@@ -553,7 +553,7 @@ def _do_update(
553553
# state filter will be used to narrow down the standard filter checking only PK
554554
state_filter = {field.attname: self.__initial_states[field.attname] for field in filter_on}
555555

556-
updated: bool = super()._do_update( # type: ignore[misc]
556+
updated: bool = super()._do_update(
557557
base_qs=base_qs.filter(**state_filter),
558558
using=using,
559559
pk_val=pk_val,

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ extend-select = [
6767
"RET",
6868
"C",
6969
# "B",
70+
"TCH", # trailing comma
7071
]
71-
fixable = ["I"]
72+
fixable = ["I", "TCH"]
7273

7374

7475
[tool.ruff.lint.isort]

0 commit comments

Comments
 (0)