Skip to content

Commit 11b88b2

Browse files
committed
try fix CI
1 parent 55ff52b commit 11b88b2

File tree

10 files changed

+106
-118
lines changed

10 files changed

+106
-118
lines changed

.github/workflows/lint.yml

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,12 @@ jobs:
4444
run: |
4545
poetry config virtualenvs.in-project true
4646
poetry run pip install --upgrade pip
47-
poetry install -E all
48-
poetry run pip install -U "Django~=${{ matrix.django-version }}"
49-
- name: Conditionally Install django-filter
50-
run: |
51-
if [ $(echo "${{ matrix.django-version }}" | awk '{print ($1 < 4.2)}') -eq 1 ]; then
52-
poetry run pip install -U "django-filter~=23.5"
53-
fi
47+
sed -i 's/^python = .*/python = "^${{ matrix.python-version }}"/' pyproject.toml
48+
poetry add django@^${{ matrix.django-version }}
49+
poetry install --no-interaction -E all
50+
5451
- name: Run Static Analysis
5552
run: |
56-
poetry run isort django_enum --check
57-
poetry run black django_enum --check
58-
poetry run pylint django_enum
59-
poetry run mypy django_enum
60-
poetry check
61-
poetry run pip check
62-
poetry run safety check --full-report
63-
poetry run python -m readme_renderer ./README.rst -o /tmp/README.html
64-
cd ./doc
65-
poetry run doc8 --ignore-path build --max-line-length 100
53+
source .venv/bin/activate
54+
./check.sh --no-fix
55+
echo "$(poetry env info --path)/bin" >> $GITHUB_PATH

check.sh

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

1515
poetry run mypy django_enum
16-
poetry run pyright
1716
poetry check
1817
poetry run pip check
1918
cd ./doc

django_enum/choices.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ class DjangoEnumPropertiesMeta(EnumPropertiesMeta, ChoicesType): # type: ignore
3535
"""
3636

3737
@property
38-
def names(cls):
38+
def names(self):
3939
"""
4040
For some eccentric enums list(Enum) is empty, so we override names
4141
if empty
4242
"""
43-
return super().names or names(cls, override=True)
43+
return super().names or names(self, override=True)
4444

4545
@property
46-
def choices(cls):
46+
def choices(self):
4747
"""
4848
For some eccentric enums list(Enum) is empty, so we override
4949
choices if empty
5050
"""
51-
return super().choices or choices(cls, override=True)
51+
return super().choices or choices(self, override=True)
5252

5353
class DjangoSymmetricMixin(SymmetricMixin):
5454
"""
@@ -58,7 +58,7 @@ class DjangoSymmetricMixin(SymmetricMixin):
5858

5959
_symmetric_builtins_ = ["name", "label"]
6060

61-
class TextChoices( # pylint: disable=too-many-ancestors
61+
class TextChoices(
6262
DjangoSymmetricMixin, DjangoTextChoices, metaclass=DjangoEnumPropertiesMeta
6363
):
6464
"""
@@ -69,7 +69,7 @@ class TextChoices( # pylint: disable=too-many-ancestors
6969
def __hash__(self):
7070
return DjangoTextChoices.__hash__(self)
7171

72-
class IntegerChoices( # pylint: disable=too-many-ancestors
72+
class IntegerChoices(
7373
DjangoSymmetricMixin, DjangoIntegerChoices, metaclass=DjangoEnumPropertiesMeta
7474
):
7575
"""
@@ -118,7 +118,7 @@ def __hash__(self):
118118
class MissingEnumProperties(enum.Enum):
119119
"""Throw error if choice types are used without enum-properties"""
120120

121-
def __init__(self, *args, **kwargs): # pylint: disable=W0231
121+
def __init__(self, *args, **kwargs):
122122
raise ImportError(
123123
f"{self.__class__.__name__} requires enum-properties to be "
124124
f"installed."
@@ -134,7 +134,7 @@ class DjangoEnumPropertiesMeta(ChoicesType): # type: ignore
134134
the ImportError.
135135
"""
136136

137-
def __init__(cls, *args, **kwargs): # pylint: disable=W0231
137+
def __init__(cls, *args, **kwargs):
138138
raise ImportError(
139139
f"{cls.__class__.__name__} requires enum-properties to be "
140140
f"installed."

django_enum/fields.py

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pylint: disable=C0302
21
"""
32
Support for Django model fields built from enumeration types.
43
"""
@@ -85,7 +84,6 @@ class _DatabaseDefault:
8584

8685
PrimitiveT = TypeVar("PrimitiveT", bound=Type[SupportedPrimitive])
8786

88-
8987
condition = "check" if django_version[0:2] < (5, 1) else "condition"
9088

9189

@@ -143,7 +141,7 @@ class EnumFieldFactory(type):
143141
based on their python Enum class types.
144142
"""
145143

146-
def __call__( # pylint: disable=C0103, R0912, R0911
144+
def __call__(
147145
cls,
148146
enum: Optional[Type[Enum]] = None,
149147
primitive: Optional[Type[SupportedPrimitive]] = None,
@@ -225,7 +223,7 @@ class EnumTypeChar(TextChoices):
225223
# make sure all enumeration values are symmetrically coercible to
226224
# the primitive, if they are not this could cause some strange behavior
227225
for value in values(enum):
228-
if value is None or type(value) is primitive: # pylint: disable=C0123
226+
if value is None or type(value) is primitive:
229227
continue
230228
try:
231229
assert type(value)(primitive(value)) == value # type: ignore
@@ -418,7 +416,7 @@ def _coerce_to_value_type(self, value: Any) -> Any:
418416
and self.primitive
419417
and not isinstance(value, self.primitive)
420418
):
421-
return self.primitive(value) # pylint: disable=E1102
419+
return self.primitive(value)
422420
return value
423421

424422
def __init__(
@@ -474,23 +472,21 @@ def _try_coerce(self, value: Any, force: bool = False) -> Union[Enum, Any]:
474472

475473
if (self.coerce or force) and not isinstance(value, self.enum):
476474
try:
477-
value = self.enum(value) # pylint: disable=E1102
475+
value = self.enum(value)
478476
except (TypeError, ValueError):
479477
try:
480478
# value = self.primitive(value)
481479
value = self._coerce_to_value_type(value)
482-
value = self.enum(value) # pylint: disable=E1102
480+
value = self.enum(value)
483481
except (TypeError, ValueError, DecimalException):
484482
try:
485483
value = self.enum[value]
486484
except KeyError as err:
487485
if len(self._value_primitives_) > 1:
488486
for primitive in self._value_primitives_:
489487
try:
490-
return self.enum( # pylint: disable=E1102
491-
primitive(value)
492-
)
493-
except Exception: # pylint: disable=W0703
488+
return self.enum(primitive(value))
489+
except Exception:
494490
pass
495491
value = self._fallback(value)
496492
if not isinstance(value, self.enum) and (
@@ -578,8 +574,8 @@ def get_db_prep_value(self, value, connection, prepared=False) -> Any:
578574
def from_db_value(
579575
self,
580576
value: Any,
581-
expression, # pylint: disable=W0613
582-
connection, # pylint: disable=W0613
577+
expression,
578+
connection,
583579
) -> Any:
584580
"""
585581
Convert the database field value into the Enum type.
@@ -663,7 +659,7 @@ def formfield(self, form_class=None, choices_form_class=None, **kwargs):
663659

664660
is_multi = self.enum and issubclass(self.enum, Flag)
665661
if is_multi and self.enum:
666-
kwargs["empty_value"] = self.enum(0) # pylint: disable=E1102
662+
kwargs["empty_value"] = self.enum(0)
667663
# why fail? - does this fail for single select too?
668664
# kwargs['show_hidden_initial'] = True
669665

@@ -694,9 +690,9 @@ def get_choices(
694690
blank_choice=tuple(BLANK_CHOICE_DASH),
695691
limit_choices_to=None,
696692
ordering=(),
697-
): # pylint: disable=W0221
693+
):
698694
if self.enum and issubclass(self.enum, Flag):
699-
blank_choice = [(self.enum(0), "---------")] # pylint: disable=E1102
695+
blank_choice = [(self.enum(0), "---------")]
700696
return [
701697
(getattr(choice, "value", choice), label)
702698
for choice, label in super().get_choices(
@@ -722,7 +718,7 @@ def constraint_name(
722718
:param enum: The enumeration type of the EnumField
723719
"""
724720
name = (
725-
f"{model_class._meta.app_label}_" # pylint: disable=W0212
721+
f"{model_class._meta.app_label}_"
726722
f"{model_class.__name__}_{field_name}_"
727723
f"{enum.__name__}"
728724
)
@@ -732,7 +728,7 @@ def constraint_name(
732728

733729
def contribute_to_class(
734730
self, cls: Type[Model], name: str, private_only: bool = False
735-
): # pylint: disable=W0221
731+
):
736732
super().contribute_to_class(cls, name, private_only=private_only)
737733
if self.constrained and self.enum and issubclass(self.enum, IntFlag):
738734
# It's possible to declare an IntFlag field with negative values -
@@ -751,20 +747,20 @@ def contribute_to_class(
751747
)
752748
if self.null:
753749
constraint |= Q(**{f"{name}__isnull": True})
754-
cls._meta.constraints = [ # pylint: disable=W0212
755-
*cls._meta.constraints, # pylint: disable=W0212
750+
cls._meta.constraints = [
751+
*cls._meta.constraints,
756752
CheckConstraint(
757-
**{
753+
**{ # type: ignore[arg-type]
758754
condition: constraint,
759755
"name": self.constraint_name(cls, name, self.enum),
760756
}
761757
),
762-
] # pylint: disable=protected-access
758+
]
763759
# this dictionary is used to serialize the model, so if constraints
764760
# is not present - they will not be added to migrations
765-
cls._meta.original_attrs.setdefault( # pylint: disable=W0212
761+
cls._meta.original_attrs.setdefault(
766762
"constraints",
767-
cls._meta.constraints, # pylint: disable=W0212
763+
cls._meta.constraints,
768764
)
769765

770766

@@ -1173,16 +1169,16 @@ def contribute_to_class(
11731169
]
11741170

11751171
if is_strict or is_conform or (is_eject and self.strict) and flags:
1176-
constraint = ( # pylint: disable=E1131
1172+
constraint = (
11771173
Q(**{f"{name}__gte": min(*flags)})
11781174
& Q(**{f"{name}__lte": reduce(or_, flags)})
11791175
) | Q(**{name: 0})
11801176

11811177
if self.null:
11821178
constraint |= Q(**{f"{name}__isnull": True})
11831179

1184-
cls._meta.constraints = [ # pylint: disable=W0212
1185-
*cls._meta.constraints, # pylint: disable=W0212
1180+
cls._meta.constraints = [
1181+
*cls._meta.constraints,
11861182
CheckConstraint(
11871183
**{
11881184
condition: constraint,
@@ -1193,9 +1189,9 @@ def contribute_to_class(
11931189
# this dictionary is used to serialize the model, so if
11941190
# constraints is not present - they will not be added to
11951191
# migrations
1196-
cls._meta.original_attrs.setdefault( # pylint: disable=W0212
1192+
cls._meta.original_attrs.setdefault(
11971193
"constraints",
1198-
cls._meta.constraints, # pylint: disable=W0212
1194+
cls._meta.constraints,
11991195
)
12001196
if isinstance(self, FlagField):
12011197
# this may have been called by a normal EnumField to bring in flag-like constraints
@@ -1283,8 +1279,8 @@ def get_db_prep_value(self, value: Any, connection, prepared=False):
12831279
def from_db_value(
12841280
self,
12851281
value: Any,
1286-
expression, # pylint: disable=W0613
1287-
connection, # pylint: disable=W0613
1282+
expression,
1283+
connection,
12881284
) -> Any:
12891285
"""
12901286
Convert the database field value into the Enum type.

django_enum/forms.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
from django.core.exceptions import ValidationError
99
from django.db.models import Choices
10-
from django.forms.fields import Field, TypedChoiceField, TypedMultipleChoiceField
10+
from django.forms.fields import (
11+
Field,
12+
TypedChoiceField,
13+
TypedMultipleChoiceField,
14+
)
1115
from django.forms.widgets import Select, SelectMultiple
1216

1317
from django_enum.utils import choices as get_choices
@@ -91,7 +95,7 @@ class NonStrictSelectMultiple(NonStrictMixin, SelectMultiple):
9195

9296
class ChoiceFieldMixin(
9397
with_typehint(TypedChoiceField) # type: ignore
94-
): # pylint: disable=R0902
98+
):
9599
"""
96100
Mixin to adapt base model form ChoiceFields to use on EnumFields.
97101
@@ -119,7 +123,7 @@ class ChoiceFieldMixin(
119123
_empty_value_overridden_: bool = False
120124
_empty_values_overridden_: bool = False
121125

122-
# choices: _ChoicesProperty
126+
choices: _ChoicesParameter
123127

124128
def __init__(
125129
self,
@@ -193,7 +197,7 @@ def enum(self):
193197
def enum(self, enum):
194198
self._enum_ = enum
195199
self._primitive_ = self._primitive_ or determine_primitive(enum)
196-
self.choices = self.choices or get_choices(self.enum) # type: ignore[has-type]
200+
self.choices = self.choices or get_choices(self.enum)
197201
# remove any of our valid enumeration values or symmetric properties
198202
# from our empty value list if there exists an equivalency
199203
if not self._empty_values_overridden_:
@@ -215,7 +219,7 @@ def enum(self, enum):
215219

216220
def _coerce_to_value_type(self, value: Any) -> Any:
217221
"""Coerce the value to the enumerations value type"""
218-
return self.primitive(value) # pylint: disable=E1102
222+
return self.primitive(value)
219223

220224
def prepare_value(self, value: Any) -> Any:
221225
"""Must return the raw enumeration value type"""
@@ -236,7 +240,7 @@ def valid_value(self, value: Any) -> bool:
236240
except ValidationError:
237241
return False
238242

239-
def default_coerce(self, value: Any) -> Any: # pylint: disable=E0202
243+
def default_coerce(self, value: Any) -> Any:
240244
"""
241245
Attempt conversion of value to an enumeration value and return it
242246
if successful.
@@ -252,7 +256,7 @@ def default_coerce(self, value: Any) -> Any: # pylint: disable=E0202
252256
one of our empty_values, or the value itself if this is a
253257
non-strict field and the value is of a matching primitive type
254258
"""
255-
if self.enum is not None and not isinstance(value, self.enum): # pylint: disable=R0801
259+
if self.enum is not None and not isinstance(value, self.enum):
256260
try:
257261
value = self.enum(value)
258262
except (TypeError, ValueError):
@@ -263,6 +267,7 @@ def default_coerce(self, value: Any) -> Any: # pylint: disable=E0202
263267
try:
264268
value = self.enum[value]
265269
except KeyError as err:
270+
assert self.primitive
266271
if self.strict or not isinstance(value, self.primitive):
267272
raise ValidationError(
268273
f"{value} is not a valid {self.enum}.",
@@ -284,15 +289,15 @@ def validate(self, value):
284289
)
285290

286291

287-
class EnumChoiceField(ChoiceFieldMixin, TypedChoiceField):
292+
class EnumChoiceField(ChoiceFieldMixin, TypedChoiceField): # type: ignore
288293
"""
289294
The default ``ChoiceField`` will only accept the base enumeration values.
290295
Use this field on forms to accept any value mappable to an enumeration
291296
including any labels or symmetric properties.
292297
"""
293298

294299

295-
class EnumFlagField(ChoiceFieldMixin, TypedMultipleChoiceField):
300+
class EnumFlagField(ChoiceFieldMixin, TypedMultipleChoiceField): # type: ignore
296301
"""
297302
The default ``TypedMultipleChoiceField`` will only accept the base
298303
enumeration values. Use this field on forms to accept any value mappable
File renamed without changes.

0 commit comments

Comments
 (0)