From b1bbbc8ce09eeb77c89ae76bf07c5a338d68fc7f Mon Sep 17 00:00:00 2001 From: Asif Saif Uddin Date: Thu, 25 Oct 2018 20:27:39 +0600 Subject: [PATCH] removed old style object inheritance, super() call and python2compat decorator from utils --- rest_framework/utils/encoders.py | 2 +- rest_framework/utils/field_mapping.py | 2 +- rest_framework/utils/mediatypes.py | 4 +--- rest_framework/utils/serializer_helpers.py | 8 ++++---- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py index faf9a08c8..9f7440989 100644 --- a/rest_framework/utils/encoders.py +++ b/rest_framework/utils/encoders.py @@ -63,4 +63,4 @@ class JSONEncoder(json.JSONEncoder): pass elif hasattr(obj, '__iter__'): return tuple(item for item in obj) - return super(JSONEncoder, self).default(obj) + return super().default(obj) diff --git a/rest_framework/utils/field_mapping.py b/rest_framework/utils/field_mapping.py index 50de3f125..ba3d19d64 100644 --- a/rest_framework/utils/field_mapping.py +++ b/rest_framework/utils/field_mapping.py @@ -16,7 +16,7 @@ NUMERIC_FIELD_TYPES = ( ) -class ClassLookupDict(object): +class ClassLookupDict: """ Takes a dictionary with classes as keys. Lookups against this object will traverses the object's inheritance diff --git a/rest_framework/utils/mediatypes.py b/rest_framework/utils/mediatypes.py index 1754fba53..e808dfa36 100644 --- a/rest_framework/utils/mediatypes.py +++ b/rest_framework/utils/mediatypes.py @@ -5,7 +5,6 @@ See https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 """ from django.http.multipartparser import parse_header -from django.utils.encoding import python_2_unicode_compatible from rest_framework import HTTP_HEADER_ENCODING @@ -45,8 +44,7 @@ def order_by_precedence(media_type_lst): return [media_types for media_types in ret if media_types] -@python_2_unicode_compatible -class _MediaType(object): +class _MediaType: def __init__(self, media_type_str): self.orig = '' if (media_type_str is None) else media_type_str self.full_type, self.params = parse_header(self.orig.encode(HTTP_HEADER_ENCODING)) diff --git a/rest_framework/utils/serializer_helpers.py b/rest_framework/utils/serializer_helpers.py index 068a37692..681d99e28 100644 --- a/rest_framework/utils/serializer_helpers.py +++ b/rest_framework/utils/serializer_helpers.py @@ -16,7 +16,7 @@ class ReturnDict(OrderedDict): def __init__(self, *args, **kwargs): self.serializer = kwargs.pop('serializer') - super(ReturnDict, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def copy(self): return ReturnDict(self, serializer=self.serializer) @@ -39,7 +39,7 @@ class ReturnList(list): def __init__(self, *args, **kwargs): self.serializer = kwargs.pop('serializer') - super(ReturnList, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def __repr__(self): return list.__repr__(self) @@ -50,7 +50,7 @@ class ReturnList(list): return (list, (list(self),)) -class BoundField(object): +class BoundField: """ A field object that also includes `.value` and `.error` properties. Returned when iterating over a serializer instance, @@ -104,7 +104,7 @@ class NestedBoundField(BoundField): def __init__(self, field, value, errors, prefix=''): if value is None or value is '': value = {} - super(NestedBoundField, self).__init__(field, value, errors, prefix) + super().__init__(field, value, errors, prefix) def __iter__(self): for field in self.fields.values():