Skip to content

clean python 2 codes #976

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

Merged
merged 17 commits into from
Oct 20, 2021
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 docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
#
# Django REST framework JSON:API documentation build configuration file, created by
# sphinx-quickstart on Fri Jul 24 23:31:15 2015.
Expand Down
2 changes: 1 addition & 1 deletion example/api/resources/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def posts(self, request):
@action(detail=True)
def manual_resource_name(self, request, *args, **kwargs):
self.resource_name = "data"
return super(Identity, self).retrieve(request, args, kwargs)
return super().retrieve(request, args, kwargs)

@action(detail=True)
def validation(self, request, *args, **kwargs):
Expand Down
2 changes: 0 additions & 2 deletions example/factories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- encoding: utf-8 -*-

import factory
from faker import Factory as FakerFactory

Expand Down
4 changes: 0 additions & 4 deletions example/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-05-02 08:26
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models

Expand Down
4 changes: 0 additions & 4 deletions example/migrations/0002_taggeditem.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-01 08:34
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models

Expand Down
4 changes: 0 additions & 4 deletions example/migrations/0003_polymorphics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-17 14:49
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models

Expand Down
4 changes: 0 additions & 4 deletions example/migrations/0004_auto_20171011_0631.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-11 06:31
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models

Expand Down
3 changes: 0 additions & 3 deletions example/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models
Expand Down
4 changes: 2 additions & 2 deletions example/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Meta:

class EntrySerializer(serializers.ModelSerializer):
def __init__(self, *args, **kwargs):
super(EntrySerializer, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
# to make testing more concise we'll only output the
# `featured` field when it's requested via `include`
request = kwargs.get("context", {}).get("request")
Expand Down Expand Up @@ -379,7 +379,7 @@ class Meta:

class CurrentProjectRelatedField(relations.PolymorphicResourceRelatedField):
def get_attribute(self, instance):
obj = super(CurrentProjectRelatedField, self).get_attribute(instance)
obj = super().get_attribute(instance)

is_art = self.field_name == "current_art_project" and isinstance(
obj, ArtProject
Expand Down
2 changes: 1 addition & 1 deletion example/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def setUp(self):
"""
Create those users
"""
super(TestBase, self).setUp()
super().setUp()
self.create_users()

def create_user(self, username, email, password="pw", first_name="", last_name=""):
Expand Down
4 changes: 0 additions & 4 deletions example/tests/snapshots/snap_test_errors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# snapshottest: v1 - https://goo.gl/zC4yUc
from __future__ import unicode_literals

from snapshottest import Snapshot

snapshots = Snapshot()
Expand Down
4 changes: 0 additions & 4 deletions example/tests/snapshots/snap_test_openapi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
# snapshottest: v1 - https://goo.gl/zC4yUc
from __future__ import unicode_literals

from snapshottest import Snapshot

snapshots = Snapshot()
Expand Down
2 changes: 1 addition & 1 deletion example/tests/test_format_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FormatKeysSetTests(TestBase):
list_url = reverse("user-list")

def setUp(self):
super(FormatKeysSetTests, self).setUp()
super().setUp()
self.detail_url = reverse("user-detail", kwargs={"pk": self.miles.pk})

def test_camelization(self):
Expand Down
2 changes: 1 addition & 1 deletion example/tests/test_generic_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GenericValidationTest(TestBase):
"""

def setUp(self):
super(GenericValidationTest, self).setUp()
super().setUp()
self.url = reverse("user-validation", kwargs={"pk": self.miles.pk})

def test_generic_validation_error(self):
Expand Down
2 changes: 1 addition & 1 deletion example/tests/test_model_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ModelViewSetTests(TestBase):
list_url = reverse("user-list")

def setUp(self):
super(ModelViewSetTests, self).setUp()
super().setUp()
self.detail_url = reverse("user-detail", kwargs={"pk": self.miles.pk})

def test_key_in_list_result(self):
Expand Down
2 changes: 1 addition & 1 deletion example/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_deserialize_many(self):
print(serializer.data)


class TestModelSerializer(object):
class TestModelSerializer:
def test_model_serializer_with_implicit_fields(self, comment, client):
expected = {
"data": {
Expand Down
2 changes: 1 addition & 1 deletion example/tests/unit/test_filter_schema_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DummyEntryViewSet(EntryViewSet):
def __init__(self, **kwargs):
# dummy up self.request since PreloadIncludesMixin expects it to be defined
self.request = None
super(DummyEntryViewSet, self).__init__(**kwargs)
super().__init__(**kwargs)


def test_filters_get_schema_params():
Expand Down
6 changes: 2 additions & 4 deletions example/tests/unit/test_renderer_class_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ class CustomRenderer(JSONRenderer):
@classmethod
def extract_attributes(cls, fields, resource):
cls.extract_attributes_was_overriden = True
return super(CustomRenderer, cls).extract_attributes(fields, resource)
return super().extract_attributes(fields, resource)

@classmethod
def extract_relationships(cls, fields, resource, resource_instance):
cls.extract_relationships_was_overriden = True
return super(CustomRenderer, cls).extract_relationships(
fields, resource, resource_instance
)
return super().extract_relationships(fields, resource, resource_instance)

assert (
CustomRenderer.build_json_resource_obj(
Expand Down
2 changes: 0 additions & 2 deletions example/tests/unit/test_serializer_method_field.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from rest_framework import serializers

from rest_framework_json_api.relations import SerializerMethodResourceRelatedField
Expand Down
10 changes: 5 additions & 5 deletions example/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_object(self):
if entry_pk is not None:
return Entry.objects.get(id=entry_pk).blog

return super(BlogViewSet, self).get_object()
return super().get_object()


class DRFBlogViewSet(ModelViewSet):
Expand All @@ -70,7 +70,7 @@ def get_object(self):
if entry_pk is not None:
return Entry.objects.get(id=entry_pk).blog

return super(DRFBlogViewSet, self).get_object()
return super().get_object()


class JsonApiViewSet(ModelViewSet):
Expand Down Expand Up @@ -98,7 +98,7 @@ def handle_exception(self, exc):
exc.status_code = HTTP_422_UNPROCESSABLE_ENTITY
# exception handler can't be set on class so you have to
# override the error response in this method
response = super(JsonApiViewSet, self).handle_exception(exc)
response = super().handle_exception(exc)
context = self.get_exception_handler_context()
return format_drf_errors(response, context, exc)

Expand All @@ -121,7 +121,7 @@ def get_object(self):
if entry_pk is not None:
return Entry.objects.exclude(pk=entry_pk).first()

return super(EntryViewSet, self).get_object()
return super().get_object()


class DRFEntryViewSet(ModelViewSet):
Expand All @@ -135,7 +135,7 @@ def get_object(self):
if entry_pk is not None:
return Entry.objects.exclude(pk=entry_pk).first()

return super(DRFEntryViewSet, self).get_object()
return super().get_object()


class NoPagination(JsonApiPageNumberPagination):
Expand Down
2 changes: 0 additions & 2 deletions rest_framework_json_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

__title__ = "djangorestframework-jsonapi"
__version__ = "4.2.1"
__author__ = ""
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_json_api/django_filters/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_schema_operation_parameters(self, view):

This is basically the reverse of `get_filterset_kwargs` above.
"""
result = super(DjangoFilterBackend, self).get_schema_operation_parameters(view)
result = super().get_schema_operation_parameters(view)
for res in result:
if "name" in res:
res["name"] = "filter[{}]".format(res["name"]).replace("__", ".")
Expand Down
4 changes: 1 addition & 3 deletions rest_framework_json_api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def remove_invalid_fields(self, queryset, fields, view, request):
else:
underscore_fields.append(undo_format_field_name(item_rewritten))

return super(OrderingFilter, self).remove_invalid_fields(
queryset, underscore_fields, view, request
)
return super().remove_invalid_fields(queryset, underscore_fields, view, request)


class QueryParameterValidationFilter(BaseFilterBackend):
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_json_api/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def parse(self, stream, media_type=None, parser_context=None):
"""
Parses the incoming bytestream as JSON and returns the resulting data
"""
result = super(JSONParser, self).parse(
result = super().parse(
stream, media_type=media_type, parser_context=parser_context
)

Expand Down
4 changes: 1 addition & 3 deletions rest_framework_json_api/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,7 @@ class BrowsableAPIRenderer(renderers.BrowsableAPIRenderer):
includes_template = "rest_framework_json_api/includes.html"

def get_context(self, data, accepted_media_type, renderer_context):
context = super(BrowsableAPIRenderer, self).get_context(
data, accepted_media_type, renderer_context
)
context = super().get_context(data, accepted_media_type, renderer_context)
view = renderer_context["view"]

context["includes_form"] = self.get_includes_form(view)
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_json_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def get_field_names(self, declared_fields, info):
field = declared_fields[field_name]
if field_name not in meta_fields:
declared[field_name] = field
fields = super(ModelSerializer, self).get_field_names(declared, info)
fields = super().get_field_names(declared, info)
return list(fields) + list(getattr(self.Meta, "meta_fields", list()))


Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
#!/usr/bin/env python3

import os
import re
Expand Down