removed old style object inheritance and super() call

This commit is contained in:
Asif Saif Uddin 2018-10-25 21:05:57 +06:00
parent 8e52e7fb17
commit 47036c0ce6
14 changed files with 70 additions and 70 deletions

View File

@ -32,7 +32,7 @@ class CSRFCheck(CsrfViewMiddleware):
return reason return reason
class BaseAuthentication(object): class BaseAuthentication:
""" """
All authentication classes should extend BaseAuthentication. All authentication classes should extend BaseAuthentication.
""" """

View File

@ -75,7 +75,7 @@ class ErrorDetail(six.text_type):
return self return self
def __eq__(self, other): def __eq__(self, other):
r = super(ErrorDetail, self).__eq__(other) r = super().__eq__(other)
try: try:
return r and self.code == other.code return r and self.code == other.code
except AttributeError: except AttributeError:
@ -195,7 +195,7 @@ class MethodNotAllowed(APIException):
def __init__(self, method, detail=None, code=None): def __init__(self, method, detail=None, code=None):
if detail is None: if detail is None:
detail = force_text(self.default_detail).format(method=method) detail = force_text(self.default_detail).format(method=method)
super(MethodNotAllowed, self).__init__(detail, code) super().__init__(detail, code)
class NotAcceptable(APIException): class NotAcceptable(APIException):
@ -205,7 +205,7 @@ class NotAcceptable(APIException):
def __init__(self, detail=None, code=None, available_renderers=None): def __init__(self, detail=None, code=None, available_renderers=None):
self.available_renderers = available_renderers self.available_renderers = available_renderers
super(NotAcceptable, self).__init__(detail, code) super().__init__(detail, code)
class UnsupportedMediaType(APIException): class UnsupportedMediaType(APIException):
@ -216,7 +216,7 @@ class UnsupportedMediaType(APIException):
def __init__(self, media_type, detail=None, code=None): def __init__(self, media_type, detail=None, code=None):
if detail is None: if detail is None:
detail = force_text(self.default_detail).format(media_type=media_type) detail = force_text(self.default_detail).format(media_type=media_type)
super(UnsupportedMediaType, self).__init__(detail, code) super().__init__(detail, code)
class Throttled(APIException): class Throttled(APIException):
@ -237,7 +237,7 @@ class Throttled(APIException):
self.extra_detail_plural.format(wait=wait), self.extra_detail_plural.format(wait=wait),
wait)))) wait))))
self.wait = wait self.wait = wait
super(Throttled, self).__init__(detail, code) super().__init__(detail, code)
def server_error(request, *args, **kwargs): def server_error(request, *args, **kwargs):

View File

@ -723,7 +723,7 @@ class NullBooleanField(Field):
def __init__(self, **kwargs): def __init__(self, **kwargs):
assert 'allow_null' not in kwargs, '`allow_null` is not a valid option.' assert 'allow_null' not in kwargs, '`allow_null` is not a valid option.'
kwargs['allow_null'] = True kwargs['allow_null'] = True
super(NullBooleanField, self).__init__(**kwargs) super().__init__(**kwargs)
def to_internal_value(self, data): def to_internal_value(self, data):
try: try:
@ -763,7 +763,7 @@ class CharField(Field):
self.trim_whitespace = kwargs.pop('trim_whitespace', True) self.trim_whitespace = kwargs.pop('trim_whitespace', True)
self.max_length = kwargs.pop('max_length', None) self.max_length = kwargs.pop('max_length', None)
self.min_length = kwargs.pop('min_length', None) self.min_length = kwargs.pop('min_length', None)
super(CharField, self).__init__(**kwargs) super().__init__(**kwargs)
if self.max_length is not None: if self.max_length is not None:
message = lazy( message = lazy(
self.error_messages['max_length'].format, self.error_messages['max_length'].format,
@ -789,7 +789,7 @@ class CharField(Field):
if not self.allow_blank: if not self.allow_blank:
self.fail('blank') self.fail('blank')
return '' return ''
return super(CharField, self).run_validation(data) return super().run_validation(data)
def to_internal_value(self, data): def to_internal_value(self, data):
# We're lenient with allowing basic numerics to be coerced into strings, # We're lenient with allowing basic numerics to be coerced into strings,
@ -810,7 +810,7 @@ class EmailField(CharField):
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(EmailField, self).__init__(**kwargs) super().__init__(**kwargs)
validator = EmailValidator(message=self.error_messages['invalid']) validator = EmailValidator(message=self.error_messages['invalid'])
self.validators.append(validator) self.validators.append(validator)
@ -821,7 +821,7 @@ class RegexField(CharField):
} }
def __init__(self, regex, **kwargs): def __init__(self, regex, **kwargs):
super(RegexField, self).__init__(**kwargs) super().__init__(**kwargs)
validator = RegexValidator(regex, message=self.error_messages['invalid']) validator = RegexValidator(regex, message=self.error_messages['invalid'])
self.validators.append(validator) self.validators.append(validator)
@ -833,7 +833,7 @@ class SlugField(CharField):
} }
def __init__(self, allow_unicode=False, **kwargs): def __init__(self, allow_unicode=False, **kwargs):
super(SlugField, self).__init__(**kwargs) super().__init__(**kwargs)
self.allow_unicode = allow_unicode self.allow_unicode = allow_unicode
if self.allow_unicode: if self.allow_unicode:
validator = RegexValidator(re.compile(r'^[-\w]+\Z', re.UNICODE), message=self.error_messages['invalid_unicode']) validator = RegexValidator(re.compile(r'^[-\w]+\Z', re.UNICODE), message=self.error_messages['invalid_unicode'])
@ -848,7 +848,7 @@ class URLField(CharField):
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(URLField, self).__init__(**kwargs) super().__init__(**kwargs)
validator = URLValidator(message=self.error_messages['invalid']) validator = URLValidator(message=self.error_messages['invalid'])
self.validators.append(validator) self.validators.append(validator)
@ -867,7 +867,7 @@ class UUIDField(Field):
'Invalid format for uuid representation. ' 'Invalid format for uuid representation. '
'Must be one of "{0}"'.format('", "'.join(self.valid_formats)) 'Must be one of "{0}"'.format('", "'.join(self.valid_formats))
) )
super(UUIDField, self).__init__(**kwargs) super().__init__(**kwargs)
def to_internal_value(self, data): def to_internal_value(self, data):
if not isinstance(data, uuid.UUID): if not isinstance(data, uuid.UUID):
@ -899,7 +899,7 @@ class IPAddressField(CharField):
def __init__(self, protocol='both', **kwargs): def __init__(self, protocol='both', **kwargs):
self.protocol = protocol.lower() self.protocol = protocol.lower()
self.unpack_ipv4 = (self.protocol == 'both') self.unpack_ipv4 = (self.protocol == 'both')
super(IPAddressField, self).__init__(**kwargs) super().__init__(**kwargs)
validators, error_message = ip_address_validators(protocol, self.unpack_ipv4) validators, error_message = ip_address_validators(protocol, self.unpack_ipv4)
self.validators.extend(validators) self.validators.extend(validators)
@ -914,7 +914,7 @@ class IPAddressField(CharField):
except DjangoValidationError: except DjangoValidationError:
self.fail('invalid', value=data) self.fail('invalid', value=data)
return super(IPAddressField, self).to_internal_value(data) return super().to_internal_value(data)
# Number types... # Number types...
@ -932,7 +932,7 @@ class IntegerField(Field):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.max_value = kwargs.pop('max_value', None) self.max_value = kwargs.pop('max_value', None)
self.min_value = kwargs.pop('min_value', None) self.min_value = kwargs.pop('min_value', None)
super(IntegerField, self).__init__(**kwargs) super().__init__(**kwargs)
if self.max_value is not None: if self.max_value is not None:
message = lazy( message = lazy(
self.error_messages['max_value'].format, self.error_messages['max_value'].format,
@ -972,7 +972,7 @@ class FloatField(Field):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.max_value = kwargs.pop('max_value', None) self.max_value = kwargs.pop('max_value', None)
self.min_value = kwargs.pop('min_value', None) self.min_value = kwargs.pop('min_value', None)
super(FloatField, self).__init__(**kwargs) super().__init__(**kwargs)
if self.max_value is not None: if self.max_value is not None:
message = lazy( message = lazy(
self.error_messages['max_value'].format, self.error_messages['max_value'].format,
@ -1030,7 +1030,7 @@ class DecimalField(Field):
else: else:
self.max_whole_digits = None self.max_whole_digits = None
super(DecimalField, self).__init__(**kwargs) super().__init__(**kwargs)
if self.max_value is not None: if self.max_value is not None:
message = lazy( message = lazy(
@ -1166,7 +1166,7 @@ class DateTimeField(Field):
self.input_formats = input_formats self.input_formats = input_formats
if default_timezone is not None: if default_timezone is not None:
self.timezone = default_timezone self.timezone = default_timezone
super(DateTimeField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def enforce_timezone(self, value): def enforce_timezone(self, value):
""" """
@ -1250,7 +1250,7 @@ class DateField(Field):
self.format = format self.format = format
if input_formats is not None: if input_formats is not None:
self.input_formats = input_formats self.input_formats = input_formats
super(DateField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def to_internal_value(self, value): def to_internal_value(self, value):
input_formats = getattr(self, 'input_formats', api_settings.DATE_INPUT_FORMATS) input_formats = getattr(self, 'input_formats', api_settings.DATE_INPUT_FORMATS)
@ -1316,7 +1316,7 @@ class TimeField(Field):
self.format = format self.format = format
if input_formats is not None: if input_formats is not None:
self.input_formats = input_formats self.input_formats = input_formats
super(TimeField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def to_internal_value(self, value): def to_internal_value(self, value):
input_formats = getattr(self, 'input_formats', api_settings.TIME_INPUT_FORMATS) input_formats = getattr(self, 'input_formats', api_settings.TIME_INPUT_FORMATS)
@ -1377,7 +1377,7 @@ class DurationField(Field):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.max_value = kwargs.pop('max_value', None) self.max_value = kwargs.pop('max_value', None)
self.min_value = kwargs.pop('min_value', None) self.min_value = kwargs.pop('min_value', None)
super(DurationField, self).__init__(**kwargs) super().__init__(**kwargs)
if self.max_value is not None: if self.max_value is not None:
message = lazy( message = lazy(
self.error_messages['max_value'].format, self.error_messages['max_value'].format,
@ -1419,7 +1419,7 @@ class ChoiceField(Field):
self.allow_blank = kwargs.pop('allow_blank', False) self.allow_blank = kwargs.pop('allow_blank', False)
super(ChoiceField, self).__init__(**kwargs) super().__init__(**kwargs)
def to_internal_value(self, data): def to_internal_value(self, data):
if data == '' and self.allow_blank: if data == '' and self.allow_blank:
@ -1472,7 +1472,7 @@ class MultipleChoiceField(ChoiceField):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.allow_empty = kwargs.pop('allow_empty', True) self.allow_empty = kwargs.pop('allow_empty', True)
super(MultipleChoiceField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def get_value(self, dictionary): def get_value(self, dictionary):
if self.field_name not in dictionary: if self.field_name not in dictionary:
@ -1491,7 +1491,7 @@ class MultipleChoiceField(ChoiceField):
self.fail('empty') self.fail('empty')
return { return {
super(MultipleChoiceField, self).to_internal_value(item) super().to_internal_value(item)
for item in data for item in data
} }
@ -1515,7 +1515,7 @@ class FilePathField(ChoiceField):
allow_folders=allow_folders, required=required allow_folders=allow_folders, required=required
) )
kwargs['choices'] = field.choices kwargs['choices'] = field.choices
super(FilePathField, self).__init__(**kwargs) super().__init__(**kwargs)
# File types... # File types...
@ -1534,7 +1534,7 @@ class FileField(Field):
self.allow_empty_file = kwargs.pop('allow_empty_file', False) self.allow_empty_file = kwargs.pop('allow_empty_file', False)
if 'use_url' in kwargs: if 'use_url' in kwargs:
self.use_url = kwargs.pop('use_url') self.use_url = kwargs.pop('use_url')
super(FileField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def to_internal_value(self, data): def to_internal_value(self, data):
try: try:
@ -1580,13 +1580,13 @@ class ImageField(FileField):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self._DjangoImageField = kwargs.pop('_DjangoImageField', DjangoImageField) self._DjangoImageField = kwargs.pop('_DjangoImageField', DjangoImageField)
super(ImageField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def to_internal_value(self, data): def to_internal_value(self, data):
# Image validation is a bit grungy, so we'll just outright # Image validation is a bit grungy, so we'll just outright
# defer to Django's implementation so we don't need to # defer to Django's implementation so we don't need to
# consider it, or treat PIL as a test dependency. # consider it, or treat PIL as a test dependency.
file_object = super(ImageField, self).to_internal_value(data) file_object = super().to_internal_value(data)
django_field = self._DjangoImageField() django_field = self._DjangoImageField()
django_field.error_messages = self.error_messages django_field.error_messages = self.error_messages
return django_field.clean(file_object) return django_field.clean(file_object)
@ -1596,7 +1596,7 @@ class ImageField(FileField):
class _UnvalidatedField(Field): class _UnvalidatedField(Field):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(_UnvalidatedField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.allow_blank = True self.allow_blank = True
self.allow_null = True self.allow_null = True
@ -1629,7 +1629,7 @@ class ListField(Field):
"Remove `source=` from the field declaration." "Remove `source=` from the field declaration."
) )
super(ListField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.child.bind(field_name='', parent=self) self.child.bind(field_name='', parent=self)
if self.max_length is not None: if self.max_length is not None:
message = self.error_messages['max_length'].format(max_length=self.max_length) message = self.error_messages['max_length'].format(max_length=self.max_length)
@ -1702,7 +1702,7 @@ class DictField(Field):
"Remove `source=` from the field declaration." "Remove `source=` from the field declaration."
) )
super(DictField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.child.bind(field_name='', parent=self) self.child.bind(field_name='', parent=self)
def get_value(self, dictionary): def get_value(self, dictionary):
@ -1752,7 +1752,7 @@ class HStoreField(DictField):
child = CharField(allow_blank=True, allow_null=True) child = CharField(allow_blank=True, allow_null=True)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(HStoreField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
assert isinstance(self.child, CharField), ( assert isinstance(self.child, CharField), (
"The `child` argument must be an instance of `CharField`, " "The `child` argument must be an instance of `CharField`, "
"as the hstore extension stores values as strings." "as the hstore extension stores values as strings."
@ -1766,7 +1766,7 @@ class JSONField(Field):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.binary = kwargs.pop('binary', False) self.binary = kwargs.pop('binary', False)
super(JSONField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def get_value(self, dictionary): def get_value(self, dictionary):
if html.is_html_input(dictionary) and self.field_name in dictionary: if html.is_html_input(dictionary) and self.field_name in dictionary:
@ -1819,7 +1819,7 @@ class ReadOnlyField(Field):
def __init__(self, **kwargs): def __init__(self, **kwargs):
kwargs['read_only'] = True kwargs['read_only'] = True
super(ReadOnlyField, self).__init__(**kwargs) super().__init__(**kwargs)
def to_representation(self, value): def to_representation(self, value):
return value return value
@ -1836,7 +1836,7 @@ class HiddenField(Field):
def __init__(self, **kwargs): def __init__(self, **kwargs):
assert 'default' in kwargs, 'default is a required argument.' assert 'default' in kwargs, 'default is a required argument.'
kwargs['write_only'] = True kwargs['write_only'] = True
super(HiddenField, self).__init__(**kwargs) super().__init__(**kwargs)
def get_value(self, dictionary): def get_value(self, dictionary):
# We always use the default value for `HiddenField`. # We always use the default value for `HiddenField`.
@ -1866,7 +1866,7 @@ class SerializerMethodField(Field):
self.method_name = method_name self.method_name = method_name
kwargs['source'] = '*' kwargs['source'] = '*'
kwargs['read_only'] = True kwargs['read_only'] = True
super(SerializerMethodField, self).__init__(**kwargs) super().__init__(**kwargs)
def bind(self, field_name, parent): def bind(self, field_name, parent):
# In order to enforce a consistent style, we error if a redundant # In order to enforce a consistent style, we error if a redundant
@ -1884,7 +1884,7 @@ class SerializerMethodField(Field):
if self.method_name is None: if self.method_name is None:
self.method_name = default_method_name self.method_name = default_method_name
super(SerializerMethodField, self).bind(field_name, parent) super().bind(field_name, parent)
def to_representation(self, value): def to_representation(self, value):
method = getattr(self.parent, self.method_name) method = getattr(self.parent, self.method_name)
@ -1907,7 +1907,7 @@ class ModelField(Field):
# The `max_length` option is supported by Django's base `Field` class, # The `max_length` option is supported by Django's base `Field` class,
# so we'd better support it here. # so we'd better support it here.
max_length = kwargs.pop('max_length', None) max_length = kwargs.pop('max_length', None)
super(ModelField, self).__init__(**kwargs) super().__init__(**kwargs)
if max_length is not None: if max_length is not None:
message = lazy( message = lazy(
self.error_messages['max_length'].format, self.error_messages['max_length'].format,

View File

@ -22,7 +22,7 @@ from rest_framework.compat import (
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
class BaseFilterBackend(object): class BaseFilterBackend:
""" """
A base class from which all filter backend classes should inherit. A base class from which all filter backend classes should inherit.
""" """

View File

@ -18,7 +18,7 @@ from rest_framework.request import clone_request
from rest_framework.utils.field_mapping import ClassLookupDict from rest_framework.utils.field_mapping import ClassLookupDict
class BaseMetadata(object): class BaseMetadata:
def determine_metadata(self, request, view): def determine_metadata(self, request, view):
""" """
Return a dictionary of metadata about the view. Return a dictionary of metadata about the view.

View File

@ -10,7 +10,7 @@ from rest_framework.response import Response
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
class CreateModelMixin(object): class CreateModelMixin:
""" """
Create a model instance. Create a model instance.
""" """
@ -31,7 +31,7 @@ class CreateModelMixin(object):
return {} return {}
class ListModelMixin(object): class ListModelMixin:
""" """
List a queryset. List a queryset.
""" """
@ -47,7 +47,7 @@ class ListModelMixin(object):
return Response(serializer.data) return Response(serializer.data)
class RetrieveModelMixin(object): class RetrieveModelMixin:
""" """
Retrieve a model instance. Retrieve a model instance.
""" """
@ -57,7 +57,7 @@ class RetrieveModelMixin(object):
return Response(serializer.data) return Response(serializer.data)
class UpdateModelMixin(object): class UpdateModelMixin:
""" """
Update a model instance. Update a model instance.
""" """
@ -83,7 +83,7 @@ class UpdateModelMixin(object):
return self.update(request, *args, **kwargs) return self.update(request, *args, **kwargs)
class DestroyModelMixin(object): class DestroyModelMixin:
""" """
Destroy a model instance. Destroy a model instance.
""" """

View File

@ -12,7 +12,7 @@ from rest_framework.utils.mediatypes import (
) )
class BaseContentNegotiation(object): class BaseContentNegotiation:
def select_parser(self, request, parsers): def select_parser(self, request, parsers):
raise NotImplementedError('.select_parser() must be implemented') raise NotImplementedError('.select_parser() must be implemented')

View File

@ -132,7 +132,7 @@ PageLink = namedtuple('PageLink', ['url', 'number', 'is_active', 'is_break'])
PAGE_BREAK = PageLink(url=None, number=None, is_active=False, is_break=True) PAGE_BREAK = PageLink(url=None, number=None, is_active=False, is_break=True)
class BasePagination(object): class BasePagination:
display_page_controls = False display_page_controls = False
def paginate_queryset(self, queryset, request, view=None): # pragma: no cover def paginate_queryset(self, queryset, request, view=None): # pragma: no cover

View File

@ -24,13 +24,13 @@ from rest_framework.settings import api_settings
from rest_framework.utils import json from rest_framework.utils import json
class DataAndFiles(object): class DataAndFiles:
def __init__(self, data, files): def __init__(self, data, files):
self.data = data self.data = data
self.files = files self.files = files
class BaseParser(object): class BaseParser:
""" """
All parsers should extend `BaseParser`, specifying a `media_type` All parsers should extend `BaseParser`, specifying a `media_type`
attribute, and overriding the `.parse()` method. attribute, and overriding the `.parse()` method.

View File

@ -115,7 +115,7 @@ class RelatedField(Field):
) )
kwargs.pop('many', None) kwargs.pop('many', None)
kwargs.pop('allow_empty', None) kwargs.pop('allow_empty', None)
super(RelatedField, self).__init__(**kwargs) super().__init__(**kwargs)
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):
# We override this method in order to automagically create # We override this method in order to automagically create
@ -151,7 +151,7 @@ class RelatedField(Field):
# We force empty strings to None values for relational fields. # We force empty strings to None values for relational fields.
if data == '': if data == '':
data = None data = None
return super(RelatedField, self).run_validation(data) return super().run_validation(data)
def get_queryset(self): def get_queryset(self):
queryset = self.queryset queryset = self.queryset
@ -183,7 +183,7 @@ class RelatedField(Field):
pass pass
# Standard case, return the object instance. # Standard case, return the object instance.
return super(RelatedField, self).get_attribute(instance) return super().get_attribute(instance)
def get_choices(self, cutoff=None): def get_choices(self, cutoff=None):
queryset = self.get_queryset() queryset = self.get_queryset()
@ -230,7 +230,7 @@ class StringRelatedField(RelatedField):
def __init__(self, **kwargs): def __init__(self, **kwargs):
kwargs['read_only'] = True kwargs['read_only'] = True
super(StringRelatedField, self).__init__(**kwargs) super().__init__(**kwargs)
def to_representation(self, value): def to_representation(self, value):
return six.text_type(value) return six.text_type(value)
@ -245,7 +245,7 @@ class PrimaryKeyRelatedField(RelatedField):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.pk_field = kwargs.pop('pk_field', None) self.pk_field = kwargs.pop('pk_field', None)
super(PrimaryKeyRelatedField, self).__init__(**kwargs) super().__init__(**kwargs)
def use_pk_only_optimization(self): def use_pk_only_optimization(self):
return True return True
@ -291,7 +291,7 @@ class HyperlinkedRelatedField(RelatedField):
# implicit `self` argument to be passed. # implicit `self` argument to be passed.
self.reverse = reverse self.reverse = reverse
super(HyperlinkedRelatedField, self).__init__(**kwargs) super().__init__(**kwargs)
def use_pk_only_optimization(self): def use_pk_only_optimization(self):
return self.lookup_field == 'pk' return self.lookup_field == 'pk'
@ -426,7 +426,7 @@ class HyperlinkedIdentityField(HyperlinkedRelatedField):
assert view_name is not None, 'The `view_name` argument is required.' assert view_name is not None, 'The `view_name` argument is required.'
kwargs['read_only'] = True kwargs['read_only'] = True
kwargs['source'] = '*' kwargs['source'] = '*'
super(HyperlinkedIdentityField, self).__init__(view_name, **kwargs) super().__init__(view_name, **kwargs)
def use_pk_only_optimization(self): def use_pk_only_optimization(self):
# We have the complete object instance already. We don't need # We have the complete object instance already. We don't need
@ -447,7 +447,7 @@ class SlugRelatedField(RelatedField):
def __init__(self, slug_field=None, **kwargs): def __init__(self, slug_field=None, **kwargs):
assert slug_field is not None, 'The `slug_field` argument is required.' assert slug_field is not None, 'The `slug_field` argument is required.'
self.slug_field = slug_field self.slug_field = slug_field
super(SlugRelatedField, self).__init__(**kwargs) super().__init__(**kwargs)
def to_internal_value(self, data): def to_internal_value(self, data):
try: try:
@ -496,7 +496,7 @@ class ManyRelatedField(Field):
self.html_cutoff_text or _(api_settings.HTML_SELECT_CUTOFF_TEXT) self.html_cutoff_text or _(api_settings.HTML_SELECT_CUTOFF_TEXT)
) )
assert child_relation is not None, '`child_relation` is a required argument.' assert child_relation is not None, '`child_relation` is a required argument.'
super(ManyRelatedField, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.child_relation.bind(field_name='', parent=self) self.child_relation.bind(field_name='', parent=self)
def get_value(self, dictionary): def get_value(self, dictionary):

View File

@ -789,7 +789,7 @@ class AdminRenderer(BrowsableAPIRenderer):
""" """
Render the HTML for the browsable API representation. Render the HTML for the browsable API representation.
""" """
context = super(AdminRenderer, self).get_context( context = super().get_context(
data, accepted_media_type, renderer_context data, accepted_media_type, renderer_context
) )

View File

@ -33,7 +33,7 @@ def is_form_media_type(media_type):
base_media_type == 'multipart/form-data') base_media_type == 'multipart/form-data')
class override_method(object): class override_method:
""" """
A context manager that temporarily overrides the method on a request, A context manager that temporarily overrides the method on a request,
additionally setting the `view.request` attribute. additionally setting the `view.request` attribute.
@ -80,7 +80,7 @@ def wrap_attributeerrors():
six.reraise(type(exc), exc, info[2]) six.reraise(type(exc), exc, info[2])
class Empty(object): class Empty:
""" """
Placeholder for unset attributes. Placeholder for unset attributes.
Cannot use `None`, as that may be a valid value. Cannot use `None`, as that may be a valid value.
@ -125,7 +125,7 @@ def clone_request(request, method):
return ret return ret
class ForcedAuthentication(object): class ForcedAuthentication:
""" """
This authentication class is used if the test client or request factory This authentication class is used if the test client or request factory
forcibly authenticated the request. forcibly authenticated the request.
@ -139,7 +139,7 @@ class ForcedAuthentication(object):
return (self.force_user, self.force_token) return (self.force_user, self.force_token)
class Request(object): class Request:
""" """
Wrapper allowing to enhance a standard `HttpRequest` instance. Wrapper allowing to enhance a standard `HttpRequest` instance.

View File

@ -28,7 +28,7 @@ class Response(SimpleTemplateResponse):
Setting 'renderer' and 'media_type' will typically be deferred, Setting 'renderer' and 'media_type' will typically be deferred,
For example being set automatically by the `APIView`. For example being set automatically by the `APIView`.
""" """
super(Response, self).__init__(None, status=status) super().__init__(None, status=status)
if isinstance(data, Serializer): if isinstance(data, Serializer):
msg = ( msg = (
@ -93,7 +93,7 @@ class Response(SimpleTemplateResponse):
""" """
Remove attributes from the response that shouldn't be cached. Remove attributes from the response that shouldn't be cached.
""" """
state = super(Response, self).__getstate__() state = super().__getstate__()
for key in ( for key in (
'accepted_renderer', 'renderer_context', 'resolver_match', 'accepted_renderer', 'renderer_context', 'resolver_match',
'client', 'request', 'json', 'wsgi_request' 'client', 'request', 'json', 'wsgi_request'

View File

@ -166,7 +166,7 @@ class SimpleRouter(BaseRouter):
def __init__(self, trailing_slash=True): def __init__(self, trailing_slash=True):
self.trailing_slash = '/' if trailing_slash else '' self.trailing_slash = '/' if trailing_slash else ''
super(SimpleRouter, self).__init__() super().__init__()
def get_default_basename(self, viewset): def get_default_basename(self, viewset):
""" """
@ -358,7 +358,7 @@ class DefaultRouter(SimpleRouter):
self.root_renderers = kwargs.pop('root_renderers') self.root_renderers = kwargs.pop('root_renderers')
else: else:
self.root_renderers = list(api_settings.DEFAULT_RENDERER_CLASSES) self.root_renderers = list(api_settings.DEFAULT_RENDERER_CLASSES)
super(DefaultRouter, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def get_api_root_view(self, api_urls=None): def get_api_root_view(self, api_urls=None):
""" """
@ -376,7 +376,7 @@ class DefaultRouter(SimpleRouter):
Generate the list of URL patterns, including a default root view Generate the list of URL patterns, including a default root view
for the API, and appending `.json` style format suffixes. for the API, and appending `.json` style format suffixes.
""" """
urls = super(DefaultRouter, self).get_urls() urls = super().get_urls()
if self.include_root_view: if self.include_root_view:
view = self.get_api_root_view(api_urls=urls) view = self.get_api_root_view(api_urls=urls)