Skip to content

Commit 720dfba

Browse files
author
Alexey Semashkevich
committed
Drop six
1 parent 1fb5ee4 commit 720dfba

22 files changed

+105
-131
lines changed

agnocomplete/core.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
The different agnocomplete classes to be discovered
33
"""
44
from copy import copy
5-
from six import with_metaclass
65
from abc import abstractmethod, ABCMeta
76
import logging
87

@@ -25,7 +24,7 @@
2524
logger = logging.getLogger(__name__)
2625

2726

28-
class ClassPropertyDescriptor(object):
27+
class ClassPropertyDescriptor:
2928
"""
3029
Toolkit class used to instanciate a class property.
3130
"""
@@ -114,7 +113,7 @@ def load_settings_sizes():
114113
)
115114

116115

117-
class AgnocompleteBase(with_metaclass(ABCMeta, object)):
116+
class AgnocompleteBase(metaclass=ABCMeta):
118117
"""
119118
Base class for Agnocomplete tools.
120119
"""
@@ -284,7 +283,7 @@ def selected(self, ids):
284283
return list(result)
285284

286285

287-
class AgnocompleteModelBase(with_metaclass(ABCMeta, AgnocompleteBase)):
286+
class AgnocompleteModelBase(AgnocompleteBase, metaclass=ABCMeta):
288287

289288
model = None
290289
requires_authentication = False
@@ -349,7 +348,7 @@ def get_queryset(self):
349348
"""
350349

351350
def __init__(self, *args, **kwargs):
352-
super(AgnocompleteModel, self).__init__(*args, **kwargs)
351+
super().__init__(*args, **kwargs)
353352
self.__final_queryset = None
354353

355354
def _construct_qs_filter(self, field_name):
@@ -515,7 +514,7 @@ def selected(self, ids):
515514
return result
516515

517516

518-
class AgnocompleteUrlProxy(with_metaclass(ABCMeta, AgnocompleteBase)):
517+
class AgnocompleteUrlProxy(AgnocompleteBase, metaclass=ABCMeta):
519518
"""
520519
This class serves as a proxy between your application and a 3rd party
521520
URL (typically a REST HTTP API).

agnocomplete/fields.py

+14-22
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
44
"""
55
from django import forms
6-
7-
import six
8-
96
from .core import AgnocompleteBase
107
from .constants import AGNOCOMPLETE_USER_ATTRIBUTE
118
from .widgets import AgnocompleteSelect, AgnocompleteMultiSelect
@@ -22,7 +19,7 @@
2219
]
2320

2421

25-
class AgnocompleteMixin(object):
22+
class AgnocompleteMixin:
2623
"""
2724
Handles the Agnocomplete generic handling for fields.
2825
"""
@@ -55,7 +52,7 @@ class SearchForm(forms.Form):
5552
5653
"""
5754
# If string, use register to fetch the class
58-
if isinstance(klass_or_instance, six.string_types):
55+
if isinstance(klass_or_instance, str):
5956
registry = get_agnocomplete_registry()
6057
if klass_or_instance not in registry:
6158
raise UnregisteredAgnocompleteException(
@@ -100,16 +97,15 @@ def clean(self, *args, **kwargs):
10097
the user context.
10198
"""
10299
self.transmit_agnocomplete_context()
103-
return super(AgnocompleteMixin, self).clean(*args, **kwargs)
100+
return super().clean(*args, **kwargs)
104101

105102

106-
class AgnocompleteContextQuerysetMixin(object):
103+
class AgnocompleteContextQuerysetMixin:
107104
def transmit_agnocomplete_context(self):
108105
"""
109106
We'll reset the current queryset only if the user is set.
110107
"""
111-
user = super(AgnocompleteContextQuerysetMixin, self) \
112-
.transmit_agnocomplete_context()
108+
user = super().transmit_agnocomplete_context()
113109
if user:
114110
self.queryset = self.agnocomplete.get_queryset()
115111
return user
@@ -121,8 +117,7 @@ class AgnocompleteField(AgnocompleteMixin, forms.ChoiceField):
121117
"""
122118
def __init__(self, agnocomplete, user=None, **kwargs):
123119
self.set_agnocomplete(agnocomplete, user)
124-
super(AgnocompleteField, self).__init__(
125-
choices=self.agnocomplete.get_choices(), **kwargs)
120+
super().__init__(choices=self.agnocomplete.get_choices(), **kwargs)
126121
self._setup_agnocomplete_widget()
127122

128123

@@ -134,8 +129,7 @@ class AgnocompleteModelField(AgnocompleteContextQuerysetMixin,
134129
"""
135130
def __init__(self, agnocomplete, user=None, **kwargs):
136131
self.set_agnocomplete(agnocomplete, user)
137-
super(AgnocompleteModelField, self).__init__(
138-
self.agnocomplete.get_choices(), **kwargs)
132+
super().__init__(self.agnocomplete.get_choices(), **kwargs)
139133
self._setup_agnocomplete_widget()
140134

141135

@@ -147,7 +141,7 @@ class AgnocompleteMultipleMixin(AgnocompleteMixin):
147141
clean_empty = True
148142

149143
def _setup_agnocomplete_widget(self):
150-
super(AgnocompleteMultipleMixin, self)._setup_agnocomplete_widget()
144+
super()._setup_agnocomplete_widget()
151145
# self.widget is a thing here
152146
self.widget.create = self.create
153147

@@ -163,7 +157,7 @@ def empty_value(self):
163157
def to_python(self, value):
164158
# Pre-clean the list value
165159
value = self.clear_list_value(value)
166-
value = super(AgnocompleteMultipleMixin, self).to_python(value)
160+
value = super().to_python(value)
167161
# return the new cleaned value or the default empty_value
168162
return value or self.empty_value
169163

@@ -189,8 +183,7 @@ def __init__(self, agnocomplete, user=None,
189183
create=False, create_field=False, **kwargs):
190184
self.set_agnocomplete(agnocomplete, user)
191185
self.set_create_field(create=create, create_field=create_field)
192-
super(AgnocompleteMultipleField, self).__init__(
193-
choices=self.agnocomplete.get_choices(), **kwargs)
186+
super().__init__(choices=self.agnocomplete.get_choices(), **kwargs)
194187
self._setup_agnocomplete_widget()
195188

196189

@@ -204,8 +197,7 @@ def __init__(self, agnocomplete, user=None,
204197
create=False, create_field=False, **kwargs):
205198
self.set_agnocomplete(agnocomplete, user)
206199
self.set_create_field(create=create, create_field=create_field)
207-
super(AgnocompleteModelMultipleField, self).__init__(
208-
self.agnocomplete.get_choices(), **kwargs)
200+
super().__init__(self.agnocomplete.get_choices(), **kwargs)
209201
self._setup_agnocomplete_widget()
210202
self._new_values = []
211203

@@ -255,7 +247,7 @@ def clean(self, value):
255247
"""
256248
if not self.create:
257249
# No new value can be created, use the regular clean field
258-
return super(AgnocompleteModelMultipleField, self).clean(value)
250+
return super().clean(value)
259251

260252
# We have to do this here before the call to "super".
261253
# It'll be called again, but we can't find a way to "pre_clean" the
@@ -266,12 +258,12 @@ def clean(self, value):
266258
pks = [v for v in value if v.isdigit()]
267259
self._new_values = [v for v in value if not v.isdigit()]
268260

269-
qs = super(AgnocompleteModelMultipleField, self).clean(pks)
261+
qs = super().clean(pks)
270262

271263
return qs
272264

273265

274-
class AgnocompleteUrlProxyMixin(object):
266+
class AgnocompleteUrlProxyMixin:
275267
"""
276268
This mixin can be used with a field which actually using
277269
:class:`agnocomplete.core.AutocompletUrlProxy`. The main purpose is to

agnocomplete/forms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .constants import AGNOCOMPLETE_USER_ATTRIBUTE
22

33

4-
class UserContextFormMixin(object):
4+
class UserContextFormMixin:
55
"""
66
Form Mixin that passes the user context to its fields.
77
@@ -14,7 +14,7 @@ class UserContextFormMixin(object):
1414
"""
1515
def __init__(self, user, *args, **kwargs):
1616
self.user = user
17-
super(UserContextFormMixin, self).__init__(*args, **kwargs)
17+
super().__init__(*args, **kwargs)
1818
if self.user:
1919
for field in self.fields.values():
2020
setattr(field, AGNOCOMPLETE_USER_ATTRIBUTE, self.user)

agnocomplete/views.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Agnocomplete views.
33
"""
4-
from six import with_metaclass
54
from abc import abstractmethod, ABCMeta
65
from django.core.exceptions import PermissionDenied, SuspiciousOperation
76
from django.http import Http404, JsonResponse
@@ -46,7 +45,7 @@ def get_error(exc):
4645
return 500, exc
4746

4847

49-
class AgnocompleteJSONView(with_metaclass(ABCMeta, View)):
48+
class AgnocompleteJSONView(View, metaclass=ABCMeta):
5049
"""
5150
Generic toolbox for JSON-returning views
5251
"""
@@ -94,7 +93,7 @@ def get(self, *args, **kwargs):
9493
)
9594

9695

97-
class RegistryMixin(object):
96+
class RegistryMixin:
9897
"""
9998
This mixin is able to return the agnocomplete registry.
10099
"""
@@ -106,7 +105,7 @@ def registry(self):
106105
return get_agnocomplete_registry()
107106

108107

109-
class UserContextFormViewMixin(object):
108+
class UserContextFormViewMixin:
110109
"""
111110
This mixin is injecting the context variable into the form kwargs
112111
"""
@@ -127,7 +126,7 @@ def get_form_kwargs(self):
127126
:meth:`get_agnocomplete_context`. Override this method to adjust it to
128127
your needs.
129128
"""
130-
data = super(UserContextFormViewMixin, self).get_form_kwargs()
129+
data = super().get_form_kwargs()
131130
data.update({
132131
'user': self.get_agnocomplete_context(),
133132
})

agnocomplete/widgets.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
]
1818

1919

20-
class AgnocompleteWidgetMixin(object):
20+
class AgnocompleteWidgetMixin:
2121
def _agnocomplete_build_attrs(self, attrs):
2222
data_url = reverse_lazy(
2323
'{}:agnocomplete'.format(get_namespace()),
@@ -42,15 +42,14 @@ def _agnocomplete_build_attrs(self, attrs):
4242
Generic toolset for building Agnocomplete-ready widgets
4343
"""
4444
def build_attrs(self, base_attrs, extra_attrs=None):
45-
attrs = super(AgnocompleteWidgetMixin, self).build_attrs(
46-
base_attrs, extra_attrs)
45+
attrs = super().build_attrs(base_attrs, extra_attrs)
4746
return self._agnocomplete_build_attrs(attrs)
4847

4948
"""
5049
Render only selected options
5150
"""
5251
def optgroups(self, name, value, attrs=None):
53-
selected_ids = set(text(v) for v in value)
52+
selected_ids = {text(v) for v in value}
5453
selected_choices = self.agnocomplete.selected(selected_ids)
5554
options = []
5655
groups = [
@@ -89,12 +88,11 @@ class AgnocompleteMultiSelect(AgnocompleteWidgetMixin, widgets.SelectMultiple):
8988
A multi-selection-ready Select widget Mixin
9089
"""
9190
def __init__(self, create=False, *args, **kwargs):
92-
super(AgnocompleteMultiSelect, self).__init__(*args, **kwargs)
91+
super().__init__(*args, **kwargs)
9392
self.create = create
9493

9594
def _agnocomplete_build_attrs(self, attrs):
96-
attrs = super(AgnocompleteMultiSelect, self). \
97-
_agnocomplete_build_attrs(attrs)
95+
attrs = super()._agnocomplete_build_attrs(attrs)
9896

9997
if self.create:
10098
attrs.update({'data-create': 'on'})

demo/authentication.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .models import Person
99

1010

11-
class PersonBackend(object):
11+
class PersonBackend:
1212
"""
1313
Authenticate against the Person model.
1414
"""

demo/autocomplete.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AutocompleteColor(AgnocompleteChoices):
2929
class AutocompleteColorExtra(AutocompleteColor):
3030
def items(self, query, **kwargs):
3131
extra_argument = kwargs.get('extra_argument', None)
32-
result = super(AutocompleteColorExtra, self).items(query, **kwargs)
32+
result = super().items(query, **kwargs)
3333
# This is a very dummy usage of the extra argument
3434
if extra_argument:
3535
result.append({'value': 'EXTRA', 'label': 'EXTRA'})
@@ -91,7 +91,7 @@ class AutocompletePersonShort(AutocompletePerson):
9191

9292
class AutocompletePersonLabel(AutocompletePerson):
9393
def label(self, current_item):
94-
return u'{item} {mail}'.format(
94+
return '{item} {mail}'.format(
9595
item=text(current_item), mail=current_item.email)
9696

9797

@@ -131,7 +131,7 @@ def selected(self, ids):
131131
# Introducing a new variable here, to make sure the
132132
# "account_registrations" property is able to fetch the matricules.
133133
self._selected_queryset = self.get_queryset()
134-
return super(AutocompletePersonDomainSpecial, self).selected(ids)
134+
return super().selected(ids)
135135

136136

137137
# Do not register this, it's for custom view demo
@@ -236,8 +236,7 @@ class AutocompleteUrlSimpleAuth(AutocompleteUrlMixin):
236236
url_search_string = 'url-proxy:simple-auth'
237237

238238
def get_http_call_kwargs(self, query):
239-
query_args = super(
240-
AutocompleteUrlSimpleAuth, self).get_http_call_kwargs(query)
239+
query_args = super().get_http_call_kwargs(query)
241240
query_args['auth_token'] = GOODAUTHTOKEN
242241
return query_args
243242

@@ -278,7 +277,7 @@ class AutocompleteUrlSkipItem(AutocompleteUrlSimple):
278277
def item(self, obj):
279278
if obj['label'] == 'first person':
280279
raise SkipItem
281-
return super(AutocompleteUrlSkipItem, self).item(obj)
280+
return super().item(obj)
282281

283282
def get_item_url(self, pk):
284283
return '{}{}'.format(

demo/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class PersonEmailSearchForm(forms.Form):
118118
to_field_name='email')
119119

120120

121-
class UrlProxyFormMixin(object):
121+
class UrlProxyFormMixin:
122122
help_text = """
123123
We're not using the usual fixture here. Here's our "database":
124124
-------

demo/models.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def save(self, *args, **kwargs):
2929
if "update_fields" in kwargs:
3030
if 'last_login' in kwargs['update_fields']:
3131
kwargs['update_fields'].remove('last_login')
32-
return super(Person, self).save(*args, **kwargs)
32+
return super().save(*args, **kwargs)
3333

3434

3535
class FavoriteColor(models.Model):
@@ -54,9 +54,9 @@ class PersonTag(models.Model):
5454
tags = models.ManyToManyField(Tag)
5555

5656
def __unicode__(self):
57-
return u"{} is tagged: {}".format(
57+
return "{} is tagged: {}".format(
5858
self.person,
59-
u", ".join([force_str(t) for t in self.tags.all()]) or u"Nothing"
59+
", ".join([force_str(t) for t in self.tags.all()]) or "Nothing"
6060
)
6161
__str__ = __unicode__
6262

@@ -66,7 +66,7 @@ class ContextTag(models.Model):
6666
domain = models.CharField(max_length=100)
6767

6868
def __unicode__(self):
69-
return u"[{}] {}".format(
69+
return "[{}] {}".format(
7070
self.domain,
7171
self.name
7272
)
@@ -78,8 +78,8 @@ class PersonContextTag(models.Model):
7878
tags = models.ManyToManyField(ContextTag)
7979

8080
def __unicode__(self):
81-
return u"{} is tagged: {}".format(
81+
return "{} is tagged: {}".format(
8282
self.person,
83-
u", ".join([force_str(t) for t in self.tags.all()]) or u"Nothing"
83+
", ".join([force_str(t) for t in self.tags.all()]) or "Nothing"
8484
)
8585
__str__ = __unicode__

0 commit comments

Comments
 (0)