Skip to content

Commit 55ff52b

Browse files
committed
switch to ruff for linting and formatting fix #62
1 parent 4ff8bc4 commit 55ff52b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+372
-762
lines changed

check.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if [ "$1" == "--no-fix" ]; then
77
poetry run ruff check
88
else
99
poetry run ruff format
10-
poetry run ruff format --line-length 80 examples
10+
#poetry run ruff format --line-length 80 examples
1111
poetry run ruff check --fix --select I
1212
poetry run ruff check --fix
1313
fi

django_enum/choices.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
from django_enum.utils import choices, names
1616

17-
1817
ChoicesType = (
1918
model_enums.ChoicesType
20-
if django_version[0:2] >= (5, 0) else
21-
model_enums.ChoicesMeta
19+
if django_version[0:2] >= (5, 0)
20+
else model_enums.ChoicesMeta
2221
)
2322

2423
DEFAULT_BOUNDARY = getattr(enum, "KEEP", None)
@@ -115,7 +114,6 @@ def __hash__(self):
115114
return enum.IntFlag.__hash__(self)
116115

117116
except (ImportError, ModuleNotFoundError):
118-
119117
# 3.11 - extend from Enum so base type check does not throw type error
120118
class MissingEnumProperties(enum.Enum):
121119
"""Throw error if choice types are used without enum-properties"""

django_enum/converters.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
class _EnumConverter:
17-
1817
enum: Type[Enum]
1918
prop: str = "value"
2019
primitive: type

django_enum/fields.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"""
33
Support for Django model fields built from enumeration types.
44
"""
5+
56
import sys
67
from datetime import date, datetime, time, timedelta
78
from decimal import Decimal, DecimalException
89
from enum import Enum, Flag, IntFlag
910
from functools import reduce
1011
from operator import or_
1112
from typing import Any, Generic, List, Optional, Tuple, Type, TypeVar, Union
13+
1214
from django import VERSION as django_version
1315
from django.core.exceptions import ValidationError
1416
from django.core.validators import DecimalValidator
@@ -654,7 +656,6 @@ def validate(self, value: Any, model_instance: Optional[Model]):
654656
) from err
655657

656658
def formfield(self, form_class=None, choices_form_class=None, **kwargs):
657-
658659
# super().formfield deletes anything unrecognized from kwargs that
659660
# we try to pass in. Very annoying because we have to
660661
# un-encapsulate some of this initialization logic, this makes our
@@ -752,15 +753,18 @@ def contribute_to_class(
752753
constraint |= Q(**{f"{name}__isnull": True})
753754
cls._meta.constraints = [ # pylint: disable=W0212
754755
*cls._meta.constraints, # pylint: disable=W0212
755-
CheckConstraint(**{
756-
condition: constraint,
757-
"name": self.constraint_name(cls, name, self.enum)
758-
}),
756+
CheckConstraint(
757+
**{
758+
condition: constraint,
759+
"name": self.constraint_name(cls, name, self.enum),
760+
}
761+
),
759762
] # pylint: disable=protected-access
760763
# this dictionary is used to serialize the model, so if constraints
761764
# is not present - they will not be added to migrations
762765
cls._meta.original_attrs.setdefault( # pylint: disable=W0212
763-
"constraints", cls._meta.constraints # pylint: disable=W0212
766+
"constraints",
767+
cls._meta.constraints, # pylint: disable=W0212
764768
)
765769

766770

@@ -1169,7 +1173,6 @@ def contribute_to_class(
11691173
]
11701174

11711175
if is_strict or is_conform or (is_eject and self.strict) and flags:
1172-
11731176
constraint = ( # pylint: disable=E1131
11741177
Q(**{f"{name}__gte": min(*flags)})
11751178
& Q(**{f"{name}__lte": reduce(or_, flags)})
@@ -1180,16 +1183,19 @@ def contribute_to_class(
11801183

11811184
cls._meta.constraints = [ # pylint: disable=W0212
11821185
*cls._meta.constraints, # pylint: disable=W0212
1183-
CheckConstraint(**{
1184-
condition: constraint,
1185-
"name": self.constraint_name(cls, name, self.enum),
1186-
}),
1186+
CheckConstraint(
1187+
**{
1188+
condition: constraint,
1189+
"name": self.constraint_name(cls, name, self.enum),
1190+
}
1191+
),
11871192
]
11881193
# this dictionary is used to serialize the model, so if
11891194
# constraints is not present - they will not be added to
11901195
# migrations
11911196
cls._meta.original_attrs.setdefault( # pylint: disable=W0212
1192-
"constraints", cls._meta.constraints # pylint: disable=W0212
1197+
"constraints",
1198+
cls._meta.constraints, # pylint: disable=W0212
11931199
)
11941200
if isinstance(self, FlagField):
11951201
# this may have been called by a normal EnumField to bring in flag-like constraints

django_enum/forms.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,7 @@ def default_coerce(self, value: Any) -> Any: # pylint: disable=E0202
252252
one of our empty_values, or the value itself if this is a
253253
non-strict field and the value is of a matching primitive type
254254
"""
255-
if self.enum is not None and not isinstance(
256-
value, self.enum
257-
): # pylint: disable=R0801
255+
if self.enum is not None and not isinstance(value, self.enum): # pylint: disable=R0801
258256
try:
259257
value = self.enum(value)
260258
except (TypeError, ValueError):

doc/source/changelog.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ v2.0.0
66
======
77

88
* Completed `Reorganize tests <https://github.com/bckohan/django-enum/issues/70>`_
9-
* Implemented `Add database constraints on enum fields by default. <https://github.com/bckohan/django-enum/issues/45>`_
10-
* Implemented `Provide an optional enum path converter. <https://github.com/bckohan/django-enum/issues/22>`_
9+
* Completed `Switch linting and formatting to ruff <https://github.com/bckohan/django-enum/issues/62>`_
1110
* Implemented `Supply a mixin for DRF ModelSerializers that instantiates the provided DRF EnumField type for model EnumFields. <https://github.com/bckohan/django-enum/issues/47>`_
12-
* Implemented `Add support for date, datetime, timedelta, time and Decimal enumeration types. <https://github.com/bckohan/django-enum/issues/43>`_
1311
* Implemented `EnumField's should inherit from common base titled EnumField <https://github.com/bckohan/django-enum/issues/46>`_
14-
* Implemented `Provide parameter to override integer range on EnumField. <https://github.com/bckohan/django-enum/issues/38>`_
15-
* Implemented `Add all official supported Django RDBMS backends to CI <https://github.com/bckohan/django-enum/issues/33>`_
12+
* Implemented `Add database constraints on enum fields by default. <https://github.com/bckohan/django-enum/issues/45>`_
1613
* Fixed `to_python() raises ValueError instead of spec'ed ValidationError <https://github.com/bckohan/django-enum/issues/44>`_
17-
* Fixed `When coerce is false, to_python does not convert to the Enum's primitive type <https://github.com/bckohan/django-enum/issues/39>`_
14+
* Implemented `Add support for date, datetime, timedelta, time and Decimal enumeration types. <https://github.com/bckohan/django-enum/issues/43>`_
1815
* Fixed `None should be an allowable enumeration value in enums of any primitive type. <https://github.com/bckohan/django-enum/issues/42>`_
16+
* Fixed `When coerce is false, to_python does not convert to the Enum's primitive type <https://github.com/bckohan/django-enum/issues/39>`_
17+
* Implemented `Provide parameter to override integer range on EnumField. <https://github.com/bckohan/django-enum/issues/38>`_
18+
* Implemented `Add all official supported Django RDBMS backends to CI <https://github.com/bckohan/django-enum/issues/33>`_
19+
* Implemented `Provide an optional enum path converter. <https://github.com/bckohan/django-enum/issues/22>`_
1920

2021

2122
v1.3.3

manage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
import os
3+
34
from django.core import management
45

56

67
def main():
7-
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
8+
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings"
89
management.execute_from_command_line()
910

1011

0 commit comments

Comments
 (0)