Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced super(ClassName, self) with super(). #821

Merged
merged 1 commit into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django_filters/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

class FieldLookupError(FieldError):
def __init__(self, model_field, lookup_expr):
super(FieldLookupError, self).__init__(
super().__init__(
"Unsupported lookup '%s' for field '%s'." % (lookup_expr, model_field)
)
34 changes: 17 additions & 17 deletions django_filters/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, fields=None, *args, **kwargs):
fields = (
forms.DecimalField(),
forms.DecimalField())
super(RangeField, self).__init__(fields, *args, **kwargs)
super().__init__(fields, *args, **kwargs)

def compress(self, data_list):
if data_list:
Expand All @@ -40,7 +40,7 @@ def __init__(self, *args, **kwargs):
fields = (
forms.DateField(),
forms.DateField())
super(DateRangeField, self).__init__(fields, *args, **kwargs)
super().__init__(fields, *args, **kwargs)

def compress(self, data_list):
if data_list:
Expand All @@ -66,7 +66,7 @@ def __init__(self, *args, **kwargs):
fields = (
forms.DateTimeField(),
forms.DateTimeField())
super(DateTimeRangeField, self).__init__(fields, *args, **kwargs)
super().__init__(fields, *args, **kwargs)


class TimeRangeField(RangeField):
Expand All @@ -76,7 +76,7 @@ def __init__(self, *args, **kwargs):
fields = (
forms.TimeField(),
forms.TimeField())
super(TimeRangeField, self).__init__(fields, *args, **kwargs)
super().__init__(fields, *args, **kwargs)


class Lookup(namedtuple('Lookup', ('value', 'lookup_type'))):
Expand All @@ -99,7 +99,7 @@ def __init__(self, field, lookup_choices, *args, **kwargs):
widget = LookupTypeWidget(**defaults)
kwargs['widget'] = widget
kwargs['help_text'] = field.help_text
super(LookupTypeField, self).__init__(fields, *args, **kwargs)
super().__init__(fields, *args, **kwargs)

def compress(self, data_list):
if len(data_list) == 2:
Expand Down Expand Up @@ -127,7 +127,7 @@ def strptime(self, value, format):
if parsed is None: # Continue with other formats if doesn't match
raise ValueError
return handle_timezone(parsed)
return super(IsoDateTimeField, self).strptime(value, format)
return super().strptime(value, format)


class BaseCSVField(forms.Field):
Expand All @@ -146,7 +146,7 @@ def __init__(self, *args, **kwargs):
widget = kwargs.get('widget') or self.widget
kwargs['widget'] = self._get_widget_class(widget)

super(BaseCSVField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def _get_widget_class(self, widget):
# passthrough, allows for override
Expand Down Expand Up @@ -179,7 +179,7 @@ class BaseRangeField(BaseCSVField):
}

def clean(self, value):
value = super(BaseRangeField, self).clean(value)
value = super().clean(value)

if value is not None and len(value) != 2:
raise forms.ValidationError(
Expand Down Expand Up @@ -219,7 +219,7 @@ class ModelChoiceIterator(forms.models.ModelChoiceIterator):
# empty choice, but before the remainder of the choices.

def __iter__(self):
iterable = super(ModelChoiceIterator, self).__iter__()
iterable = super().__iter__()

if self.field.empty_label is not None:
yield next(iterable)
Expand All @@ -232,21 +232,21 @@ def __iter__(self):

def __len__(self):
add = 1 if self.field.null_label is not None else 0
return super(ModelChoiceIterator, self).__len__() + add
return super().__len__() + add


class ChoiceIteratorMixin(object):
def __init__(self, *args, **kwargs):
self.null_label = kwargs.pop('null_label', settings.NULL_CHOICE_LABEL)
self.null_value = kwargs.pop('null_value', settings.NULL_CHOICE_VALUE)

super(ChoiceIteratorMixin, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def _get_choices(self):
return super(ChoiceIteratorMixin, self)._get_choices()
return super()._get_choices()

def _set_choices(self, value):
super(ChoiceIteratorMixin, self)._set_choices(value)
super()._set_choices(value)
value = self.iterator(self, self._choices)

self._choices = self.widget.choices = value
Expand All @@ -259,15 +259,15 @@ class ChoiceField(ChoiceIteratorMixin, forms.ChoiceField):

def __init__(self, *args, **kwargs):
self.empty_label = kwargs.pop('empty_label', settings.EMPTY_CHOICE_LABEL)
super(ChoiceField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class MultipleChoiceField(ChoiceIteratorMixin, forms.MultipleChoiceField):
iterator = ChoiceIterator

def __init__(self, *args, **kwargs):
self.empty_label = None
super(MultipleChoiceField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class ModelChoiceField(ChoiceIteratorMixin, forms.ModelChoiceField):
Expand All @@ -277,7 +277,7 @@ def to_python(self, value):
# bypass the queryset value check
if self.null_label is not None and value == self.null_value:
return value
return super(ModelChoiceField, self).to_python(value)
return super().to_python(value)


class ModelMultipleChoiceField(ChoiceIteratorMixin, forms.ModelMultipleChoiceField):
Expand All @@ -288,6 +288,6 @@ def _check_values(self, value):
if null: # remove the null value and any potential duplicates
value = [v for v in value if v != self.null_value]

result = list(super(ModelMultipleChoiceField, self)._check_values(value))
result = list(super()._check_values(value))
result += [self.null_value] if null else []
return result
26 changes: 13 additions & 13 deletions django_filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ class ChoiceFilter(Filter):

def __init__(self, *args, **kwargs):
self.null_value = kwargs.get('null_value', settings.NULL_CHOICE_VALUE)
super(ChoiceFilter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def filter(self, qs, value):
if value != self.null_value:
return super(ChoiceFilter, self).filter(qs, value)
return super().filter(qs, value)

qs = self.get_method(qs)(**{'%s__%s' % (self.field_name, self.lookup_expr): None})
return qs.distinct() if self.distinct else qs
Expand Down Expand Up @@ -237,7 +237,7 @@ def __init__(self, *args, **kwargs):
kwargs.setdefault('distinct', True)
self.conjoined = kwargs.pop('conjoined', False)
self.null_value = kwargs.get('null_value', settings.NULL_CHOICE_VALUE)
super(MultipleChoiceFilter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def is_noop(self, qs, value):
"""
Expand Down Expand Up @@ -342,7 +342,7 @@ class EmployeeFilter(filters.FilterSet):
"""
def __init__(self, *args, **kwargs):
self.queryset = kwargs.get('queryset')
super(QuerySetRequestMixin, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def get_request(self):
try:
Expand All @@ -365,15 +365,15 @@ def field(self):
if queryset is not None:
self.extra['queryset'] = queryset

return super(QuerySetRequestMixin, self).field
return super().field


class ModelChoiceFilter(QuerySetRequestMixin, ChoiceFilter):
field_class = ModelChoiceField

def __init__(self, *args, **kwargs):
kwargs.setdefault('empty_label', settings.EMPTY_CHOICE_LABEL)
super(ModelChoiceFilter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class ModelMultipleChoiceFilter(QuerySetRequestMixin, MultipleChoiceFilter):
Expand Down Expand Up @@ -457,7 +457,7 @@ def __init__(self, *args, **kwargs):
# empty/null choices not relevant
kwargs.setdefault('empty_label', None)
kwargs.setdefault('null_label', None)
super(DateRangeFilter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def filter(self, qs, value):
try:
Expand Down Expand Up @@ -490,7 +490,7 @@ def field(self):
qs = self.model._default_manager.distinct()
qs = qs.order_by(self.field_name).values_list(self.field_name, flat=True)
self.extra['choices'] = [(o, o) for o in qs]
return super(AllValuesFilter, self).field
return super().field


class AllValuesMultipleFilter(MultipleChoiceFilter):
Expand All @@ -499,7 +499,7 @@ def field(self):
qs = self.model._default_manager.distinct()
qs = qs.order_by(self.field_name).values_list(self.field_name, flat=True)
self.extra['choices'] = [(o, o) for o in qs]
return super(AllValuesMultipleFilter, self).field
return super().field


class BaseCSVFilter(Filter):
Expand All @@ -510,7 +510,7 @@ class BaseCSVFilter(Filter):

def __init__(self, *args, **kwargs):
kwargs.setdefault('help_text', _('Multiple values may be separated by commas.'))
super(BaseCSVFilter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

class ConcreteCSVField(self.base_field_class, self.field_class):
pass
Expand Down Expand Up @@ -551,15 +551,15 @@ class BaseInFilter(BaseCSVFilter):

def __init__(self, *args, **kwargs):
kwargs.setdefault('lookup_expr', 'in')
super(BaseInFilter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class BaseRangeFilter(BaseCSVFilter):
base_field_class = BaseRangeField

def __init__(self, *args, **kwargs):
kwargs.setdefault('lookup_expr', 'range')
super(BaseRangeFilter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class OrderingFilter(BaseCSVFilter, ChoiceFilter):
Expand Down Expand Up @@ -607,7 +607,7 @@ def __init__(self, *args, **kwargs):
kwargs.setdefault('label', _('Ordering'))
kwargs.setdefault('help_text', '')
kwargs.setdefault('null_label', None)
super(OrderingFilter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def get_ordering_value(self, param):
descending = param.startswith('-')
Expand Down
2 changes: 1 addition & 1 deletion django_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FilterSetMetaclass(type):
def __new__(cls, name, bases, attrs):
attrs['declared_filters'] = cls.get_declared_filters(bases, attrs)

new_class = super(FilterSetMetaclass, cls).__new__(cls, name, bases, attrs)
new_class = super().__new__(cls, name, bases, attrs)
new_class._meta = FilterSetOptions(getattr(new_class, 'Meta', None))
new_class.base_filters = new_class.get_filters()

Expand Down
2 changes: 1 addition & 1 deletion django_filters/rest_framework/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class BooleanFilter(BooleanFilter):
def __init__(self, *args, **kwargs):
kwargs.setdefault('widget', BooleanWidget)

super(BooleanFilter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
2 changes: 1 addition & 1 deletion django_filters/rest_framework/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FilterSet(filterset.FilterSet):

@property
def form(self):
form = super(FilterSet, self).form
form = super().form

if compat.is_crispy():
from crispy_forms.helper import FormHelper
Expand Down
2 changes: 1 addition & 1 deletion django_filters/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def object_filter(request, model=None, queryset=None, template_name=None,
class ECFilterView(FilterView):
"""Handle the extra_context from the functional object_filter view"""
def get_context_data(self, **kwargs):
context = super(ECFilterView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
extra_context = self.kwargs.get('extra_context') or {}
for k, v in extra_context.items():
if callable(v):
Expand Down
18 changes: 9 additions & 9 deletions django_filters/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

class LinkWidget(forms.Widget):
def __init__(self, attrs=None, choices=()):
super(LinkWidget, self).__init__(attrs)
super().__init__(attrs)

self.choices = choices

def value_from_datadict(self, data, files, name):
value = super(LinkWidget, self).value_from_datadict(data, files, name)
value = super().value_from_datadict(data, files, name)
self.data = data
return value

Expand Down Expand Up @@ -82,7 +82,7 @@ class SuffixedMultiWidget(forms.MultiWidget):
suffixes = []

def __init__(self, *args, **kwargs):
super(SuffixedMultiWidget, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

assert len(self.widgets) == len(self.suffixes)
assert len(self.suffixes) == len(set(self.suffixes))
Expand All @@ -91,7 +91,7 @@ def suffixed(self, name, suffix):
return '_'.join([name, suffix]) if suffix else name

def get_context(self, name, value, attrs):
context = super(SuffixedMultiWidget, self).get_context(name, value, attrs)
context = super().get_context(name, value, attrs)
for subcontext, suffix in zip(context['widget']['subwidgets'], self.suffixes):
subcontext['name'] = self.suffixed(name, suffix)

Expand Down Expand Up @@ -129,7 +129,7 @@ class RangeWidget(SuffixedMultiWidget):

def __init__(self, attrs=None):
widgets = (forms.TextInput, forms.TextInput)
super(RangeWidget, self).__init__(widgets, attrs)
super().__init__(widgets, attrs)

def decompress(self, value):
if value:
Expand Down Expand Up @@ -159,7 +159,7 @@ def __init__(self, attrs=None):
choices = (('', _('Unknown')),
('true', _('Yes')),
('false', _('No')))
super(BooleanWidget, self).__init__(attrs, choices)
super().__init__(attrs, choices)

def render(self, name, value, attrs=None):
try:
Expand All @@ -171,7 +171,7 @@ def render(self, name, value, attrs=None):
}[value]
except KeyError:
value = ''
return super(BooleanWidget, self).render(name, value, attrs)
return super().render(name, value, attrs)

def value_from_datadict(self, data, files, name):
value = data.get(name, None)
Expand All @@ -193,7 +193,7 @@ def _isiterable(self, value):
return isinstance(value, Iterable) and not isinstance(value, str)

def value_from_datadict(self, data, files, name):
value = super(BaseCSVWidget, self).value_from_datadict(data, files, name)
value = super().value_from_datadict(data, files, name)

if value is not None:
if value == '': # empty value should parse as an empty list
Expand All @@ -208,7 +208,7 @@ def render(self, name, value, attrs=None):
if len(value) <= 1:
# delegate to main widget (Select, etc...) if not multiple values
value = value[0] if value else ''
return super(BaseCSVWidget, self).render(name, value, attrs)
return super().render(name, value, attrs)

# if we have multiple values, we need to force render as a text input
# (otherwise, the additional values are lost)
Expand Down
2 changes: 1 addition & 1 deletion tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_internal_type(self):
def formfield(self, **kwargs):
defaults = {'form_class': forms.GenericIPAddressField}
defaults.update(kwargs)
return super(SubnetMaskField, self).formfield(**defaults)
return super().formfield(**defaults)


class User(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class Meta:
fields = ['favorite_books']

def __init__(self, *args, **kwargs):
super(F, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
# This filter has a limited number of choices.
self.filters['favorite_books'].extra.update({
'queryset': Book.objects.filter(id__in=[1, 2])
Expand Down
Loading