Skip to content

Commit 2fdb080

Browse files
committed
Enable isort + pytest (#11)
Enable pytest
1 parent d9c9564 commit 2fdb080

33 files changed

+331
-82
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ repos:
3434
- repo: https://github.com/python-poetry/poetry
3535
rev: 1.6.1
3636
hooks:
37-
- id: poetry-check
38-
- id: poetry-lock
39-
- id: poetry-export
37+
- id: poetry-check
38+
additional_dependencies:
39+
- poetry-plugin-sort==0.2.0
40+
# FIXME: poetry lock export more platform on the CI
41+
# - id: poetry-lock
42+
# args: ["--no-update"]
43+
- id: poetry-export
4044

4145
- repo: https://github.com/astral-sh/ruff-pre-commit
4246
rev: v0.0.291

django_fsm/__init__.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
"""
22
State tracking functionality for django models
33
"""
4+
from __future__ import annotations
5+
46
import inspect
5-
from functools import partialmethod, wraps
7+
from functools import partialmethod
8+
from functools import wraps
69

7-
import django
810
from django.apps import apps as django_apps
911
from django.db import models
1012
from django.db.models import Field
1113
from django.db.models.query_utils import DeferredAttribute
1214
from django.db.models.signals import class_prepared
1315

14-
from django_fsm.signals import pre_transition, post_transition
15-
16+
from django_fsm.signals import post_transition
17+
from django_fsm.signals import pre_transition
1618

1719
__all__ = [
1820
"TransitionNotAllowed",
@@ -251,26 +253,9 @@ def deconstruct(self):
251253
return name, path, args, kwargs
252254

253255
def get_state(self, instance):
254-
# The state field may be deferred. We delegate the logic of figuring
255-
# this out and loading the deferred field on-demand to Django's
256-
# built-in DeferredAttribute class. DeferredAttribute's instantiation
257-
# signature changed over time, so we need to check Django version
258-
# before proceeding to call DeferredAttribute. An alternative to this
259-
# would be copying the latest implementation of DeferredAttribute to
260-
# django_fsm, but this comes with the added responsibility of keeping
261-
# the copied code up to date.
262-
if django.VERSION[:3] >= (3, 0, 0):
263-
return DeferredAttribute(self).__get__(instance)
264-
elif django.VERSION[:3] >= (2, 1, 0):
265-
return DeferredAttribute(self.name).__get__(instance)
266-
elif django.VERSION[:3] >= (1, 10, 0):
267-
return DeferredAttribute(self.name, model=None).__get__(instance)
268-
else:
269-
# The field was either not deferred (in which case we can return it
270-
# right away) or ir was, but we are running on an unknown version
271-
# of Django and we do not know the appropriate DeferredAttribute
272-
# interface, and accessing the field will raise KeyError.
273-
return instance.__dict__[self.name]
256+
# The state field may be deferred. We delegate the logic of figuring this out
257+
# and loading the deferred field on-demand to Django's built-in DeferredAttribute class.
258+
return DeferredAttribute(self).__get__(instance)
274259

275260
def set_state(self, instance, state):
276261
instance.__dict__[self.name] = state
@@ -435,7 +420,7 @@ def set_state(self, instance, state):
435420
instance.__dict__[self.attname] = self.to_python(state)
436421

437422

438-
class FSMModelMixin(object):
423+
class FSMModelMixin:
439424
"""
440425
Mixin that allows refresh_from_db for models with fsm protected fields
441426
"""
@@ -459,9 +444,9 @@ def refresh_from_db(self, *args, **kwargs):
459444
if f.attname not in skipped_fields]
460445

461446
kwargs['fields'] = fields
462-
super(FSMModelMixin, self).refresh_from_db(*args, **kwargs)
447+
super().refresh_from_db(*args, **kwargs)
463448

464-
class ConcurrentTransitionMixin(object):
449+
class ConcurrentTransitionMixin:
465450
"""
466451
Protects a Model from undesirable effects caused by concurrently executed transitions,
467452
e.g. running the same transition multiple times at the same time, or running different

django_fsm/management/commands/graph_transitions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import graphviz
1+
from __future__ import annotations
2+
23
from itertools import chain
34

5+
import graphviz
46
from django.apps import apps
57
from django.core.management.base import BaseCommand
68
from django.utils.encoding import force_str
79

8-
from django_fsm import FSMFieldMixin, GET_STATE, RETURN_VALUE
10+
from django_fsm import GET_STATE
11+
from django_fsm import RETURN_VALUE
12+
from django_fsm import FSMFieldMixin
913

1014

1115
def all_fsm_fields_data(model):

django_fsm/signals.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from django.dispatch import Signal
24

35
pre_transition = Signal()

django_fsm/tests/test_abstract_inheritance.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from __future__ import annotations
2+
13
from django.db import models
24
from django.test import TestCase
35

4-
from django_fsm import FSMField, transition, can_proceed
6+
from django_fsm import FSMField
7+
from django_fsm import can_proceed
8+
from django_fsm import transition
59

610

711
class BaseAbstractModel(models.Model):

django_fsm/tests/test_basic_transitions.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
from __future__ import annotations
2+
13
from django.db import models
24
from django.test import TestCase
35

4-
from django_fsm import FSMField, TransitionNotAllowed, transition, can_proceed, Transition
5-
from django_fsm.signals import pre_transition, post_transition
6+
from django_fsm import FSMField
7+
from django_fsm import Transition
8+
from django_fsm import TransitionNotAllowed
9+
from django_fsm import can_proceed
10+
from django_fsm import transition
11+
from django_fsm.signals import post_transition
12+
from django_fsm.signals import pre_transition
613

714

815
class BlogPost(models.Model):

django_fsm/tests/test_conditions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
from __future__ import annotations
2+
13
from django.db import models
24
from django.test import TestCase
3-
from django_fsm import FSMField, TransitionNotAllowed, transition, can_proceed
5+
6+
from django_fsm import FSMField
7+
from django_fsm import TransitionNotAllowed
8+
from django_fsm import can_proceed
9+
from django_fsm import transition
410

511

612
def condition_func(instance):

django_fsm/tests/test_integer_field.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
from __future__ import annotations
2+
13
from django.db import models
24
from django.test import TestCase
3-
from django_fsm import FSMIntegerField, TransitionNotAllowed, transition
5+
6+
from django_fsm import FSMIntegerField
7+
from django_fsm import TransitionNotAllowed
8+
from django_fsm import transition
49

510

611
class BlogPostStateEnum:

django_fsm/tests/test_key_field.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
from __future__ import annotations
2+
13
from django.db import models
24
from django.test import TestCase
3-
from django_fsm import FSMKeyField, TransitionNotAllowed, transition, can_proceed
45

6+
from django_fsm import FSMKeyField
7+
from django_fsm import TransitionNotAllowed
8+
from django_fsm import can_proceed
9+
from django_fsm import transition
510

611
FK_AVAILABLE_STATES = (
712
("New", "_NEW_"),

django_fsm/tests/test_protected_field.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
from __future__ import annotations
2+
13
from django.db import models
24
from django.test import TestCase
35

4-
from django_fsm import FSMField, transition
6+
from django_fsm import FSMField
7+
from django_fsm import transition
58

69

710
class ProtectedAccessModel(models.Model):

0 commit comments

Comments
 (0)