Skip to content

Commit 1618537

Browse files
committed
Remove obsolete six dependency
1 parent 5fc3458 commit 1618537

File tree

8 files changed

+16
-23
lines changed

8 files changed

+16
-23
lines changed

example/requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ pluggy
88
py
99
pyparsing
1010
pytz
11-
six
1211
sqlparse
1312
django-filter>=2.0

example/tests/unit/test_utils.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from django.contrib.auth import get_user_model
33
from django.test import override_settings
4-
from django.utils import six
54
from rest_framework import serializers
65
from rest_framework.generics import GenericAPIView
76
from rest_framework.response import Response
@@ -130,7 +129,7 @@ def test_get_included_serializers_against_class():
130129
'comments': CommentSerializer,
131130
'self': klass
132131
}
133-
assert six.viewkeys(included_serializers) == six.viewkeys(klass.included_serializers), (
132+
assert included_serializers.keys() == klass.included_serializers.keys(), (
134133
'the keys must be preserved'
135134
)
136135

@@ -147,7 +146,7 @@ def test_get_included_serializers_against_instance():
147146
'comments': CommentSerializer,
148147
'self': klass
149148
}
150-
assert six.viewkeys(included_serializers) == six.viewkeys(klass.included_serializers), (
149+
assert included_serializers.keys() == klass.included_serializers.keys(), (
151150
'the keys must be preserved'
152151
)
153152

rest_framework_json_api/parsers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Parsers
33
"""
4-
from django.utils import six
54
from rest_framework import parsers
65
from rest_framework.exceptions import ParseError
76

@@ -121,7 +120,7 @@ def parse(self, stream, media_type=None, parser_context=None):
121120
if request.method in ('PUT', 'POST', 'PATCH'):
122121
resource_name = utils.get_resource_name(
123122
parser_context, expand_polymorphic_types=True)
124-
if isinstance(resource_name, six.string_types):
123+
if isinstance(resource_name, str):
125124
if data.get('type') != resource_name:
126125
raise exceptions.Conflict(
127126
"The resource object's type ({data_type}) is not the type that "

rest_framework_json_api/relations.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from collections.abc import Iterable
44

55
import inflection
6-
import six
76
from django.core.exceptions import ImproperlyConfigured
87
from django.urls import NoReverseMatch
98
from django.utils.translation import ugettext_lazy as _
@@ -210,7 +209,7 @@ def conflict(self, key, **kwargs):
210209
raise Conflict(message_string)
211210

212211
def to_internal_value(self, data):
213-
if isinstance(data, six.text_type):
212+
if isinstance(data, str):
214213
try:
215214
data = json.loads(data)
216215
except ValueError:
@@ -324,7 +323,7 @@ def use_pk_only_optimization(self):
324323
return False
325324

326325
def to_internal_value(self, data):
327-
if isinstance(data, six.text_type):
326+
if isinstance(data, str):
328327
try:
329328
data = json.loads(data)
330329
except ValueError:

rest_framework_json_api/renderers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import inflection
99
from django.db.models import Manager
10-
from django.utils import encoding, six
10+
from django.utils import encoding
1111
from rest_framework import relations, renderers
1212
from rest_framework.fields import SkipField, get_attribute
1313
from rest_framework.relations import PKOnlyObject
@@ -55,7 +55,7 @@ def extract_attributes(cls, fields, resource):
5555
Builds the `attributes` object of the JSON API resource object.
5656
"""
5757
data = OrderedDict()
58-
for field_name, field in six.iteritems(fields):
58+
for field_name, field in iter(fields.items()):
5959
# ID is always provided in the root of JSON API so remove it from attributes
6060
if field_name == 'id':
6161
continue
@@ -97,7 +97,7 @@ def extract_relationships(cls, fields, resource, resource_instance):
9797
if resource_instance is None:
9898
return
9999

100-
for field_name, field in six.iteritems(fields):
100+
for field_name, field in iter(fields.items()):
101101
# Skip URL field
102102
if field_name == api_settings.URL_FIELD_NAME:
103103
continue
@@ -331,7 +331,7 @@ def extract_included(cls, fields, resource, resource_instance, included_resource
331331
included_resources = copy.copy(included_resources)
332332
included_resources = [inflection.underscore(value) for value in included_resources]
333333

334-
for field_name, field in six.iteritems(fields):
334+
for field_name, field in iter(fields.items()):
335335
# Skip URL field
336336
if field_name == api_settings.URL_FIELD_NAME:
337337
continue

rest_framework_json_api/serializers.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import inflection
2-
import six
32
from django.db.models.query import QuerySet
43
from django.utils.translation import ugettext_lazy as _
54
from rest_framework.exceptions import ParseError
@@ -257,8 +256,7 @@ def __new__(cls, name, bases, attrs):
257256
return new_class
258257

259258

260-
@six.add_metaclass(PolymorphicSerializerMetaclass)
261-
class PolymorphicModelSerializer(ModelSerializer):
259+
class PolymorphicModelSerializer(ModelSerializer, metaclass=PolymorphicSerializerMetaclass):
262260
"""
263261
A serializer for polymorphic models.
264262
Useful for "lazy" parent models. Leaves should be represented with a regular serializer.

rest_framework_json_api/utils.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
ManyToManyDescriptor,
1212
ReverseManyToOneDescriptor
1313
)
14-
from django.utils import encoding, six
14+
from django.utils import encoding
1515
from django.utils.module_loading import import_string as import_class_from_dotted_path
1616
from django.utils.translation import ugettext_lazy as _
1717
from rest_framework import exceptions
@@ -63,7 +63,7 @@ def get_resource_name(context, expand_polymorphic_types=False):
6363
except AttributeError:
6464
resource_name = view.__class__.__name__
6565

66-
if not isinstance(resource_name, six.string_types):
66+
if not isinstance(resource_name, str):
6767
# The resource name is not a string - return as is
6868
return resource_name
6969

@@ -337,7 +337,7 @@ def get_default_included_resources_from_serializer(serializer):
337337
def get_included_serializers(serializer):
338338
included_serializers = copy.copy(getattr(serializer, 'included_serializers', dict()))
339339

340-
for name, value in six.iteritems(included_serializers):
340+
for name, value in iter(included_serializers.items()):
341341
if not isinstance(value, type):
342342
if value == 'self':
343343
included_serializers[name] = (
@@ -367,7 +367,7 @@ def get_relation_instance(resource_instance, source, serializer):
367367
return True, relation_instance
368368

369369

370-
class Hyperlink(six.text_type):
370+
class Hyperlink(str):
371371
"""
372372
A string like object that additionally has an associated name.
373373
We use this for hyperlinked URLs that may render as a named link
@@ -378,7 +378,7 @@ class Hyperlink(six.text_type):
378378
"""
379379

380380
def __new__(self, url, name):
381-
ret = six.text_type.__new__(self, url)
381+
ret = str.__new__(self, url)
382382
ret.name = name
383383
return ret
384384

@@ -405,7 +405,7 @@ def format_drf_errors(response, context, exc):
405405
# see if they passed a dictionary to ValidationError manually
406406
if isinstance(error, dict):
407407
errors.append(error)
408-
elif isinstance(error, six.string_types):
408+
elif isinstance(error, str):
409409
classes = inspect.getmembers(exceptions, inspect.isclass)
410410
# DRF sets the `field` to 'detail' for its own exceptions
411411
if isinstance(exc, tuple(x[1] for x in classes)):

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def get_package_data(package):
9696
'inflection>=0.3.0',
9797
'djangorestframework>=3.9',
9898
'django>=1.11',
99-
'six',
10099
],
101100
setup_requires=pytest_runner + sphinx + wheel,
102101
tests_require=[

0 commit comments

Comments
 (0)