Skip to content

Commit d10b179

Browse files
Petter Fribergflaeppe
Petter Friberg
authored andcommitted
Bump versions and move to GitHub actions (#1)
* Remove testing with Django<2.2 and Python<3.7 - Newer versions of mypy also (incorrectly) don't accept overriding enum attributes when subclassing. Mitigated by temporarily removing attributes from Enum base class * Move to GitHub actions
1 parent a27323e commit d10b179

File tree

12 files changed

+110
-163
lines changed

12 files changed

+110
-163
lines changed

.github/workflows/tests.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
include:
15+
- python: "3.7"
16+
tox_env: py37-django22
17+
- python: "3.7"
18+
tox_env: py37-django30
19+
- python: "3.7"
20+
tox_env: py37-django31
21+
- python: "3.8"
22+
tox_env: py38-django22
23+
- python: "3.8"
24+
tox_env: py38-django30
25+
- python: "3.8"
26+
tox_env: py38-django31
27+
- python: "3.9"
28+
tox_env: py39-django22
29+
- python: "3.9"
30+
tox_env: py39-django30
31+
- python: "3.9"
32+
tox_env: py39-django31
33+
- python: "3.7"
34+
tox_env: checks
35+
name: ${{ matrix.tox_env }}
36+
steps:
37+
- uses: actions/checkout@v2
38+
- uses: actions/setup-python@v2
39+
with:
40+
python-version: ${{ matrix.python }}
41+
- run: pip install tox
42+
- name: Run ${{ matrix.tox_env }} job
43+
run: tox -e ${{ matrix.tox_env }}

.travis.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22

33

4+
## [unreleased]
5+
6+
- Move CI to GitHub Actions
7+
- Dropped support for Python < 3.7
8+
- Dropped support for Django < 2.2
9+
410
## [2.0.2]
511

612
- Added Django 3.1 support. (Pull #63)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ black-check:
2323
black --check django_enumfield run_tests.py setup.py
2424

2525
.PHONY: checks
26-
checks: flake8 mypy black-check
26+
checks: mypy flake8 black-check
2727

2828
.PHONY: format
2929
format: black isort

django_enumfield/contrib/drf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import six
21
from django.utils.translation import ugettext_lazy as _
32
from rest_framework import serializers
43

@@ -18,7 +17,7 @@ def get_choice_value(self, enum_value):
1817
return enum_value.value
1918

2019
def to_internal_value(self, data):
21-
if isinstance(data, six.string_types) and data.isdigit():
20+
if isinstance(data, str) and data.isdigit():
2221
data = int(data)
2322

2423
try:

django_enumfield/db/fields.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from functools import partial
33
from typing import Any, Callable # noqa: F401
44

5-
import six
65
from django import forms
76
from django.db import models
87
from django.utils.encoding import force_text
@@ -19,7 +18,6 @@
1918
def partialishmethod(method):
2019
return _partialmethod(method)
2120

22-
2321
except ImportError: # pragma: no cover
2422
from django.utils.functional import curry
2523

@@ -85,7 +83,7 @@ def from_db_value(self, value, *_):
8583

8684
def to_python(self, value):
8785
if value is not None:
88-
if isinstance(value, six.text_type) and value.isdigit():
86+
if isinstance(value, str) and value.isdigit():
8987
value = int(value)
9088
return self.enum.get(value)
9189

@@ -120,10 +118,8 @@ def set_enum(self, new_value):
120118
except ValueError:
121119
raise InvalidStatusOperationError(
122120
ugettext(
123-
six.text_type(
124-
"{value!r} is not one of the available choices "
125-
"for enum {enum}."
126-
)
121+
"{value!r} is not one of the available choices "
122+
"for enum {enum}."
127123
).format(value=new_value, enum=enum)
128124
)
129125
setattr(self, private_att_name, new_value)

django_enumfield/enum.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from __future__ import absolute_import
22

33
import logging
4-
from enum import Enum as NativeEnum, IntEnum as NativeIntEnum
5-
from typing import Any, Dict, List, Optional, Sequence, Tuple, TypeVar, Union, cast
6-
7-
import six
4+
import enum
5+
from typing import Any, List, Optional, Sequence, Tuple, TypeVar, Union, cast, Mapping
6+
from django.utils.encoding import force_str
87

98
try:
109
from django.utils.functional import classproperty # type: ignore
@@ -20,7 +19,7 @@
2019
RAISE = object()
2120

2221

23-
class BlankEnum(NativeEnum):
22+
class BlankEnum(enum.Enum):
2423
BLANK = ""
2524

2625
@property
@@ -45,13 +44,12 @@ def __get__(self, instance, cls=None):
4544
T = TypeVar("T", bound="Enum")
4645

4746

48-
@six.python_2_unicode_compatible
49-
class Enum(NativeIntEnum):
50-
""" A container for holding and restoring enum values """
47+
class Enum(enum.IntEnum):
48+
"""A container for holding and restoring enum values"""
5149

52-
__labels__ = {} # type: Dict[int, six.text_type]
50+
__labels__ = {} # type: Mapping[int, str]
5351
__default__ = None # type: Optional[int]
54-
__transitions__ = {} # type: Dict[int, Sequence[int]]
52+
__transitions__ = {} # type: Mapping[int, Sequence[int]]
5553

5654
def __str__(self):
5755
return self.label
@@ -68,19 +66,20 @@ def label(self):
6866
:return: label for value
6967
:rtype: str
7068
"""
71-
label = cast(str, self.__class__.__labels__.get(self.value, self.name))
72-
return six.text_type(label)
69+
labels = self.__class__.__labels__
70+
return force_str(labels.get(self.value, self.name))
7371

74-
@classproperty
72+
@classproperty # type: ignore[arg-type]
7573
def do_not_call_in_templates(cls):
7674
# type: () -> bool
7775
# Fix for Django templates so that any lookups of enums won't fail
7876
# More info: https://stackoverflow.com/questions/35953132/how-to-access-enum-types-in-django-templates # noqa: E501
7977
return True
8078

81-
@classproperty
82-
def values(cls): # type: ignore
83-
return {member.value: member for member in cls}
79+
@classproperty # type: ignore[arg-type]
80+
def values(cls):
81+
# type: () -> Mapping[int, Enum]
82+
return {member.value: member for member in cls} # type: ignore[attr-defined]
8483

8584
def deconstruct(self):
8685
"""
@@ -103,13 +102,13 @@ def items(cls):
103102

104103
@classmethod
105104
def choices(cls, blank=False):
106-
# type: (bool) -> List[Tuple[Union[int, str], NativeEnum]]
105+
# type: (bool) -> List[Tuple[Union[int, str], enum.Enum]]
107106
"""Choices for Enum
108107
:return: List of tuples (<value>, <member>)
109108
"""
110109
choices = sorted(
111110
[(member.value, member) for member in cls], key=lambda x: x[0]
112-
) # type: List[Tuple[Union[str, int], NativeEnum]]
111+
) # type: List[Tuple[Union[str, int], enum.Enum]]
113112
if blank:
114113
choices.insert(0, (BlankEnum.BLANK.value, BlankEnum.BLANK))
115114
return choices
@@ -164,7 +163,7 @@ def get(
164163
return cls(name_or_numeric)
165164
except ValueError:
166165
pass
167-
elif isinstance(name_or_numeric, six.string_types):
166+
elif isinstance(name_or_numeric, str):
168167
try:
169168
return cls[name_or_numeric]
170169
except KeyError:
@@ -225,4 +224,5 @@ def transition_origins(cls, to_value):
225224
"""
226225
if isinstance(to_value, cls):
227226
to_value = to_value.value
228-
return cast(Sequence[int], cls.__transitions__.get(to_value, []))
227+
228+
return cls.__transitions__.get(to_value, [])

0 commit comments

Comments
 (0)