Skip to content

Commit 2e51796

Browse files
committed
Drop Python 2 support (credit @claudep)
1 parent cc6ab6d commit 2e51796

File tree

32 files changed

+51
-131
lines changed

32 files changed

+51
-131
lines changed

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Features
1111
--------
1212

13-
- Python 2.7, 3.4, Django 2.0+ support (Django 1.11 (LTS), is supported until django-autocomplete-light-3.2.10),
13+
- Python 3.4, Django 3.2+ support,
1414
- Django (multiple) choice support,
1515
- Django (multiple) model choice support,
1616
- Django generic foreign key support (through django-querysetsequence),

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def read(fname):
2929
keywords='django autocomplete',
3030
install_requires=[
3131
'django>=3.2',
32-
'six',
3332
],
3433
extras_require={
3534
'nested': ['django-nested-admin>=3.0.21'],

src/dal/test/case.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
import pytest
1515

16-
import six
17-
1816

1917
@pytest.mark.usefixtures('cls_browser')
2018
class AutocompleteTestCase(StaticLiveServerTestCase):
@@ -85,7 +83,7 @@ class OptionMixin(object):
8583
@transaction.atomic
8684
def create_option(self):
8785
"""Create a unique option from self.model into self.option."""
88-
unique_name = six.text_type(uuid.uuid1())
86+
unique_name = str(uuid.uuid1())
8987

9088
if VERSION < (1, 10):
9189
# Support for the name to be changed through a popup in the admin.

src/dal/test/stories.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
StaleElementReferenceException,
88
)
99

10-
import six
11-
1210
import tenacity
1311

1412

@@ -80,7 +78,7 @@ def get_label(self):
8078
)
8179

8280
self.clean_label_from_remove_buton()
83-
return self.clean_label(six.text_type(label.text))
81+
return self.clean_label(label.text)
8482

8583
def clean_label(self, label):
8684
"""Given an option text, return the actual label."""
@@ -89,7 +87,7 @@ def clean_label(self, label):
8987
@tenacity.retry(stop=tenacity.stop_after_delay(3))
9088
def assert_label(self, text):
9189
"""Assert that the autocomplete label matches text."""
92-
assert six.text_type(text) == six.text_type(self.get_label())
90+
assert text == self.get_label()
9391

9492
def get_value(self):
9593
"""Return the autocomplete field value."""
@@ -101,7 +99,7 @@ def get_value(self):
10199
@tenacity.retry(stop=tenacity.stop_after_delay(3))
102100
def assert_value(self, value):
103101
"""Assart that the actual field value matches value."""
104-
assert self.get_value() == six.text_type(value)
102+
assert self.get_value() == str(value)
105103

106104
def assert_selection(self, value, label):
107105
"""Assert value is selected and has the given label."""
@@ -349,7 +347,7 @@ def get_labels(self):
349347
)
350348

351349
return [
352-
self.clean_label(six.text_type(label.text))
350+
self.clean_label(label.text)
353351
for label in labels
354352
]
355353

@@ -374,8 +372,8 @@ def assert_labels(self, texts):
374372
self.case.assertEqual(len(texts), len(labels))
375373

376374
def assert_values(self, values):
377-
"""Assart that the actual field values matches values."""
378-
text_values = [six.text_type(v) for v in values]
375+
"""Assert that the actual field values matches values."""
376+
text_values = [str(v) for v in values]
379377
actual_values = self.get_values()
380378

381379
for actual_value in actual_values:

src/dal/views.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
from django.template.loader import render_to_string
1919
from django.views.generic.list import BaseListView
2020

21-
import six
22-
2321

2422
class ViewMixin(object):
2523
"""Common methods for autocomplete views.
@@ -98,7 +96,7 @@ def get_result_label(self, result):
9896
if self.template:
9997
return render_to_string(self.template, {"result": result})
10098
else:
101-
return six.text_type(result)
99+
return result
102100

103101
def get_selected_result_label(self, result):
104102
"""Return the label of a selected result."""

src/dal/widgets.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from django.core.urlresolvers import reverse
1414
from django.utils.safestring import mark_safe
1515

16-
import six
17-
1816

1917
class WidgetMixin(object):
2018
"""Base mixin for autocomplete widgets.
@@ -69,15 +67,15 @@ def build_attrs(self, *args, **kwargs):
6967
def filter_choices_to_render(self, selected_choices):
7068
"""Replace self.choices with selected_choices."""
7169
self.choices = [c for c in self.choices if
72-
six.text_type(c[0]) in selected_choices]
70+
str(c[0]) in selected_choices]
7371

7472
@staticmethod
7573
def _make_forward_dict(f):
7674
"""Convert forward declaration to a dictionary.
7775
7876
A returned dictionary will be dumped to JSON while rendering widget.
7977
"""
80-
if isinstance(f, six.string_types):
78+
if isinstance(f, str):
8179
return forward.Field(f).to_dict()
8280
elif isinstance(f, forward.Forward):
8381
return f.to_dict()
@@ -112,7 +110,7 @@ def render_options(self, *args):
112110
selected_choices_arg = 1 if VERSION < (1, 10) else 0
113111

114112
# Filter out None values, not needed for autocomplete
115-
selected_choices = [six.text_type(c) for c
113+
selected_choices = [str(c) for c
116114
in args[selected_choices_arg] if c]
117115

118116
all_choices = copy.copy(self.choices)
@@ -135,7 +133,7 @@ def optgroups(self, name, value, attrs=None):
135133
Used by Django>=1.10.
136134
"""
137135
# Filter out None values, not needed for autocomplete
138-
selected_choices = [six.text_type(c) for c in value if c]
136+
selected_choices = [str(c) for c in value if c]
139137
all_choices = copy.copy(self.choices)
140138
if self.url:
141139
self.filter_choices_to_render(selected_choices)

src/dal_contenttypes/fields.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from django.contrib.contenttypes.models import ContentType
44

5-
import six
6-
75

86
class ContentTypeModelFieldMixin(object):
97
"""
@@ -23,7 +21,7 @@ def prepare_value(self, value):
2321
if not value:
2422
return ''
2523

26-
if isinstance(value, six.string_types):
24+
if isinstance(value, str):
2725
# Apparently Django's ModelChoiceField also expects two kinds of
2826
# "value" to be passed in this method.
2927
return value

src/dal_select2/views.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from django.utils.translation import gettext as _
1515
from django.views.generic.list import View
1616

17-
import six
18-
1917

2018
class Select2ViewMixin(object):
2119
"""View mixin to render a JSON response for Select2."""
@@ -204,8 +202,7 @@ def get_item_as_group(self, entry):
204202
group = None
205203
item = entry
206204

207-
if isinstance(entry, Sequence) and \
208-
not isinstance(entry, six.string_types):
205+
if isinstance(entry, Sequence) and not isinstance(entry, str):
209206

210207
entry_length = len(entry)
211208

@@ -222,8 +219,7 @@ def get_item_as_group(self, entry):
222219
elif entry_length > 0:
223220
item = entry[0]
224221

225-
if not isinstance(item, Sequence) or \
226-
isinstance(item, six.string_types):
222+
if not isinstance(item, Sequence) or isinstance(item, str):
227223
item = (item,)
228224

229225
return (group, item),
@@ -265,7 +261,7 @@ def get(self, request, *args, **kwargs):
265261
{"id": x, "text": y} for x, y in l
266262
]
267263
}
268-
for g, l in six.iteritems(results_dict)
264+
for g, l in results_dict.items()
269265
]
270266
})
271267

@@ -293,6 +289,6 @@ def get(self, request, *args, **kwargs):
293289
{"id": x, "text": x} for x in l
294290
]
295291
}
296-
for g, l in six.iteritems(results_dict)
292+
for g, l in results_dict.items()
297293
]
298294
})

src/dal_select2/widgets.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
from django.utils import translation
2828
from django.utils.itercompat import is_iterable
2929

30-
import six
31-
3230

3331
I18N_PATH = 'autocomplete_light/i18n/'
3432

@@ -148,7 +146,7 @@ def value_from_datadict(self, data, files, name):
148146
and the model field expects a comma-separated list of tags.
149147
"""
150148
values = super(TagSelect2, self).value_from_datadict(data, files, name)
151-
return six.text_type(',').join(values)
149+
return ','.join(values)
152150

153151
def option_value(self, value):
154152
"""Return the HTML option value attribute for a value."""
@@ -164,7 +162,7 @@ def format_value(self, value):
164162
if not v:
165163
continue
166164

167-
v = v.split(',') if isinstance(v, six.string_types) else v
165+
v = v.split(',') if isinstance(v, str) else v
168166
v = [v] if not is_iterable(v) else v
169167
for t in v:
170168
values.add(self.option_value(t))
@@ -173,7 +171,7 @@ def format_value(self, value):
173171
def options(self, name, value, attrs=None):
174172
"""Return only select options."""
175173
# When the data hasn't validated, we get the raw input
176-
if isinstance(value, six.text_type):
174+
if isinstance(value, str):
177175
value = value.split(',')
178176

179177
for v in value:

src/dal_select2_queryset_sequence/views.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
from queryset_sequence import QuerySetSequence
1313

14-
import six
15-
1614

1715
class Select2QuerySetSequenceView(BaseQuerySetSequenceView, Select2ViewMixin):
1816
"""
@@ -54,7 +52,7 @@ def get_results(self, context):
5452
'text': capfirst(self.get_model_name(model)),
5553
'children': [{
5654
'id': self.get_result_value(result),
57-
'text': six.text_type(result),
55+
'text': str(result),
5856
} for result in results]
5957
} for model, results in groups.items()]
6058

src/dal_select2_taggit/widgets.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
from django import VERSION
66

7-
import six
8-
97

108
class TaggitSelect2(TagSelect2):
119
"""Select2 tag widget for taggit's TagField."""
@@ -42,7 +40,7 @@ def render_options(self, *args):
4240
selected_choices = args[selected_choices_arg]
4341

4442
# When the data hasn't validated, we get the raw input here
45-
if isinstance(selected_choices, six.text_type):
43+
if isinstance(selected_choices, str):
4644
choices = [c.strip() for c in selected_choices.split(',')]
4745
else:
4846
# Filter out None values, not needed for autocomplete

test_project/custom_select2/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from django.db import models
22

3-
from six import python_2_unicode_compatible
43

5-
6-
@python_2_unicode_compatible
74
class TModel(models.Model):
85
name = models.CharField(max_length=200)
96

test_project/forward_different_fields/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from django.db import models
22

3-
from six import python_2_unicode_compatible
43

5-
6-
@python_2_unicode_compatible
74
class TModel(models.Model):
85
name = models.CharField(max_length=200)
96

test_project/linked_data/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from django.db import models
22

3-
from six import python_2_unicode_compatible
43

5-
6-
@python_2_unicode_compatible
74
class TModel(models.Model):
85
name = models.CharField(max_length=200)
96

test_project/rename_forward/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from django.db import models
22

3-
from six import python_2_unicode_compatible
43

5-
6-
@python_2_unicode_compatible
74
class TModel(models.Model):
85
name = models.CharField(max_length=200)
96

test_project/secure_data/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from django.db import models
22

3-
from six import python_2_unicode_compatible
43

5-
6-
@python_2_unicode_compatible
74
class TModel(models.Model):
85
name = models.CharField(max_length=200)
96

test_project/select2_generic_foreign_key/models.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from django.contrib.contenttypes.fields import GenericForeignKey
22
from django.db import models
33

4-
from six import python_2_unicode_compatible
54

6-
7-
@python_2_unicode_compatible
85
class TModel(models.Model):
96
name = models.CharField(max_length=200)
107

@@ -54,7 +51,6 @@ def __str__(self):
5451
return self.name
5552

5653

57-
@python_2_unicode_compatible
5854
class TProxyModel(TModel):
5955
class Meta:
6056
proxy = True

test_project/select2_generic_foreign_key/test_forms.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
from queryset_sequence import QuerySetSequence
1212

13-
import six
14-
1513
from .forms import TForm
1614
from .models import TModel, TProxyModel
1715

@@ -84,7 +82,7 @@ def test_initial(self):
8482
# Ensure that the widget rendered right, with only the selection
8583
expected = forms.Select(
8684
choices=(
87-
(self.get_value(relation), six.text_type(relation)),
85+
(self.get_value(relation), str(relation)),
8886
),
8987
attrs={
9088
'data-autocomplete-light-function': 'select2',
@@ -93,7 +91,7 @@ def test_initial(self):
9391
'id': 'id_test',
9492
}
9593
).render('test', value=self.get_value(relation))
96-
result = six.text_type(form['test'].as_widget())
94+
result = str(form['test'].as_widget())
9795

9896
expected += '''
9997
<div class="dal-forward-conf" id="dal-forward-conf-for_id_test"

test_project/select2_generic_m2m/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
from genericm2m.models import RelatedObjectsDescriptor
44

5-
from six import python_2_unicode_compatible
65

7-
8-
@python_2_unicode_compatible
96
class TModel(models.Model):
107
name = models.CharField(max_length=200)
118

0 commit comments

Comments
 (0)