From 8e77aaccb8b931a16cd65df6f0fdce1ece02f5be Mon Sep 17 00:00:00 2001 From: Pascal F Date: Wed, 1 May 2024 13:46:21 +0200 Subject: [PATCH] Step 8 --- .pre-commit-config.yaml | 4 ++-- django_fsm/__init__.py | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2a5ecbd..a7099da 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,9 +49,9 @@ repos: - id: ruff - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.7.1 + rev: v1.10.0 hooks: - id: mypy additional_dependencies: - - django-stubs==4.2.6 + - django-stubs==5.0.0 - django-guardian diff --git a/django_fsm/__init__.py b/django_fsm/__init__.py index c1c34bf..7bf39b9 100644 --- a/django_fsm/__init__.py +++ b/django_fsm/__init__.py @@ -122,10 +122,10 @@ def has_perm(self, instance: _Instance, user: UserWithPermissions) -> bool: else: return False - def __hash__(self): + def __hash__(self) -> int: return hash(self.name) - def __eq__(self, other): + def __eq__(self, other: object) -> bool: if isinstance(other, str): return other == self.name if isinstance(other, Transition): @@ -309,7 +309,7 @@ def deconstruct(self) -> Any: def get_state(self, instance: _Instance) -> Any: # The state field may be deferred. We delegate the logic of figuring this out # and loading the deferred field on-demand to Django's built-in DeferredAttribute class. - return DeferredAttribute(self).__get__(instance) # type: ignore[attr-defined] + return DeferredAttribute(self).__get__(instance) def set_state(self, instance: _Instance, state: str) -> None: instance.__dict__[self.name] = state @@ -479,14 +479,14 @@ class FSMModelMixin(_FSMModel): Mixin that allows refresh_from_db for models with fsm protected fields """ - def _get_protected_fsm_fields(self): - def is_fsm_and_protected(f): + def _get_protected_fsm_fields(self) -> set[str]: + def is_fsm_and_protected(f: object) -> Any: return isinstance(f, FSMFieldMixin) and f.protected - protected_fields = filter(is_fsm_and_protected, self._meta.concrete_fields) + protected_fields: Iterable[Any] = filter(is_fsm_and_protected, self._meta.concrete_fields) # type: ignore[attr-defined, arg-type] return {f.attname for f in protected_fields} - def refresh_from_db(self, *args, **kwargs): + def refresh_from_db(self, *args: Any, **kwargs: Any) -> None: fields = kwargs.pop("fields", None) # Use provided fields, if not set then reload all non-deferred fields.0 @@ -495,7 +495,7 @@ def refresh_from_db(self, *args, **kwargs): protected_fields = self._get_protected_fsm_fields() skipped_fields = deferred_fields.union(protected_fields) - fields = [f.attname for f in self._meta.concrete_fields if f.attname not in skipped_fields] + fields = [f.attname for f in self._meta.concrete_fields if f.attname not in skipped_fields] # type: ignore[attr-defined] kwargs["fields"] = fields super().refresh_from_db(*args, **kwargs) @@ -538,9 +538,9 @@ def state_fields(self) -> Iterable[Any]: def _do_update( self, base_qs: QuerySet[Self], - using: Any, + using: str | None, pk_val: Any, - values: Collection[Any] | None, + values: Collection[tuple[_Field, type[models.Model] | None, Any]], update_fields: Iterable[str] | None, forced_update: bool, ) -> bool: @@ -553,7 +553,7 @@ def _do_update( # state filter will be used to narrow down the standard filter checking only PK state_filter = {field.attname: self.__initial_states[field.attname] for field in filter_on} - updated: bool = super()._do_update( # type: ignore[misc] + updated: bool = super()._do_update( base_qs=base_qs.filter(**state_filter), using=using, pk_val=pk_val,