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

Drop "six" package #374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions dynamic_rest/datastructures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""This module contains custom data-structures."""
import six


class TreeMap(dict):
Expand All @@ -15,7 +14,7 @@ def get_paths(self):
A list of lists of paths.
"""
paths = []
for key, child in six.iteritems(self):
for key, child in self.items():
if isinstance(child, TreeMap) and child:
# current child is an intermediate node
for path in child.get_paths():
Expand Down
5 changes: 2 additions & 3 deletions dynamic_rest/fields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import importlib
import pickle

import six
from django.core.exceptions import ObjectDoesNotExist
from django.utils.functional import cached_property
from rest_framework import fields
Expand Down Expand Up @@ -245,7 +244,7 @@ def _inherit_parent_kwargs(self, kwargs):
def get_serializer(self, *args, **kwargs):
"""Get an instance of the child serializer."""
init_args = {
k: v for k, v in six.iteritems(self.kwargs)
k: v for k, v in self.kwargs.items()
if k in self.SERIALIZER_KWARGS
}

Expand Down Expand Up @@ -353,7 +352,7 @@ def serializer_class(self):
Resolves string imports.
"""
serializer_class = self._serializer_class
if not isinstance(serializer_class, six.string_types):
if not isinstance(serializer_class, str):
return serializer_class

parts = serializer_class.split('.')
Expand Down
17 changes: 8 additions & 9 deletions dynamic_rest/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.core.exceptions import ValidationError as InternalValidationError
from django.core.exceptions import ImproperlyConfigured
from django.db.models import Q, Prefetch, Manager
import six
from functools import reduce
from rest_framework import __version__ as drf_version
from rest_framework import serializers
Expand Down Expand Up @@ -53,7 +52,7 @@ def has_joins(queryset):
If this is the case, it is possible for the queryset
to return duplicate results.
"""
for join in six.itervalues(queryset.query.alias_map):
for join in queryset.query.alias_map.values():
if join.join_type:
return True
return False
Expand Down Expand Up @@ -277,7 +276,7 @@ def _get_requested_filters(self, **kwargs):
if getattr(self, 'view', None):
out['_complex'] = self.view.get_request_feature(self.view.FILTER, raw=True)

for spec, value in six.iteritems(filters_map):
for spec, value in filters_map.items():

# Inclusion or exclusion?
if spec[0] == '-':
Expand Down Expand Up @@ -309,7 +308,7 @@ def _get_requested_filters(self, **kwargs):
pass
elif operator in self.VALID_FILTER_OPERATORS:
value = value[0]
if operator == 'isnull' and isinstance(value, six.string_types):
if operator == 'isnull' and isinstance(value, str):
value = is_truthy(value)
elif operator == 'eq':
operator = None
Expand Down Expand Up @@ -360,7 +359,7 @@ def _filters_to_query(self, filters, serializer, q=None):
q &= Q(**includes)
if excludes:
excludes = rewrite_filters(excludes, serializer)
for k, v in six.iteritems(excludes):
for k, v in excludes.items():
q &= ~Q(**{k: v})
return q
else:
Expand Down Expand Up @@ -391,8 +390,8 @@ def _create_prefetch(self, source, queryset):
def _build_implicit_prefetches(self, model, prefetches, requirements):
"""Build a prefetch dictionary based on internal requirements."""

for source, remainder in six.iteritems(requirements):
if not remainder or isinstance(remainder, six.string_types):
for source, remainder in requirements.items():
if not remainder or isinstance(remainder, str):
# no further requirements to prefetch
continue

Expand Down Expand Up @@ -429,7 +428,7 @@ def _build_requested_prefetches(
):
"""Build a prefetch dictionary based on request requirements."""

for name, field in six.iteritems(fields):
for name, field in fields.items():
original_field = field
if isinstance(field, DynamicRelationField):
field = field.serializer
Expand Down Expand Up @@ -480,7 +479,7 @@ def _build_requested_prefetches(

def _get_implicit_requirements(self, fields, requirements):
"""Extract internal prefetch requirements from serializer fields."""
for name, field in six.iteritems(fields):
for name, field in fields.items():
source = field.source
# Requires may be manually set on the field -- if not,
# assume the field requires only its source.
Expand Down
3 changes: 1 addition & 2 deletions dynamic_rest/links.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""This module contains utilities to support API links."""
import six
from dynamic_rest.conf import settings
from dynamic_rest.routers import DynamicRouter

Expand All @@ -20,7 +19,7 @@ def merge_link_object(serializer, data, instance):
return data

link_fields = serializer.get_link_fields()
for name, field in six.iteritems(link_fields):
for name, field in link_fields.items():
# For included fields, omit link if there's no data.
if name in data and not data[name]:
continue
Expand Down
3 changes: 1 addition & 2 deletions dynamic_rest/processors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""This module contains response processors."""
from collections import defaultdict

import six
from rest_framework.serializers import ListSerializer
from rest_framework.utils.serializer_helpers import ReturnDict

Expand Down Expand Up @@ -96,7 +95,7 @@ def process(self, obj, parent=None, parent_key=None, depth=0):
returned = isinstance(obj, ReturnDict)
if dynamic or returned:
# recursively check all fields
for key, o in six.iteritems(obj):
for key, o in obj.items():
if isinstance(o, list) or isinstance(o, dict):
# lists or dicts indicate a relation
self.process(
Expand Down
10 changes: 4 additions & 6 deletions dynamic_rest/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
except ImportError:
from django.core.urlresolvers import get_script_prefix

import six

import rest_framework
from rest_framework import views
from rest_framework.response import Response
Expand Down Expand Up @@ -60,12 +58,12 @@ def sort_key(r):
# structure, for now it is capped at a single level
# for UX reasons
for group_name, endpoints in sorted(
six.iteritems(directory),
directory.items(),
key=sort_key
):
endpoints_list = []
for endpoint_name, endpoint in sorted(
six.iteritems(endpoints),
endpoints.items(),
key=sort_key
):
if endpoint_name[:1] == '_':
Expand Down Expand Up @@ -331,15 +329,15 @@ class UserSerializer(..):
return routes

serializer = viewset.serializer_class()
fields = getattr(serializer, 'get_link_fields', lambda: [])()
fields = getattr(serializer, 'get_link_fields', lambda: {})()

route_name = '{basename}-{methodnamehyphen}'
if drf_version >= (3, 8, 0):
route_compat_kwargs = {'detail': False}
else:
route_compat_kwargs = {}

for field_name, field in six.iteritems(fields):
for field_name, field in fields.items():
methodname = 'list_related'
url = (
r'^{prefix}/{lookup}/(?P<field_name>%s)'
Expand Down
15 changes: 7 additions & 8 deletions dynamic_rest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import inflection
from django.db import models
import six
from django.utils.functional import cached_property
from rest_framework import __version__ as drf_version
from rest_framework import exceptions, fields, serializers
Expand Down Expand Up @@ -236,7 +235,7 @@ def __init__(
# passes null as a value, remove the field from the data
# this addresses the frontends that send
# undefined resource fields as null on POST/PUT
for field_name, field in six.iteritems(self.get_all_fields()):
for field_name, field in self.get_all_fields().items():
if (
field.allow_null is False and
field.required is False and
Expand Down Expand Up @@ -304,7 +303,7 @@ def _dynamic_init(self, only_fields, include_fields, exclude_fields):
# First exclude all, then add back in explicitly included fields.
include_fields = set(
list(include_fields) + [
field for field, val in six.iteritems(self.request_fields)
field for field, val in self.request_fields.items()
if val or val == {}
]
)
Expand Down Expand Up @@ -393,11 +392,11 @@ def _all_fields(self):
FIELDS_CACHE[self.__class__] = all_fields
else:
all_fields = copy.copy(FIELDS_CACHE[self.__class__])
for k, field in six.iteritems(all_fields):
for k, field in all_fields.items():
if hasattr(field, 'reset'):
field.reset()

for k, field in six.iteritems(all_fields):
for k, field in all_fields.items():
field.field_name = k
field.parent = self

Expand All @@ -411,7 +410,7 @@ def _get_flagged_field_names(self, fields, attr, meta_attr=None):
meta_attr = '%s_fields' % attr
meta_list = set(getattr(self.Meta, meta_attr, []))
return {
name for name, field in six.iteritems(fields)
name for name, field in fields.items()
if getattr(field, attr, None) is True or name in
meta_list
}
Expand Down Expand Up @@ -460,7 +459,7 @@ def get_fields(self):

# apply request overrides
if request_fields:
for name, include in six.iteritems(request_fields):
for name, include in request_fields.items():
if name not in serializer_fields:
raise exceptions.ParseError(
'"%s" is not a valid field name for "%s".' %
Expand Down Expand Up @@ -520,7 +519,7 @@ def _link_fields(self):
else:
all_fields = self.get_all_fields()
return {
name: field for name, field in six.iteritems(all_fields)
name: field for name, field in all_fields.items()
if isinstance(field, DynamicRelationField) and
getattr(field, 'link', True) and
not (
Expand Down
4 changes: 1 addition & 3 deletions dynamic_rest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from hashids import Hashids

from six import string_types

from dynamic_rest.conf import settings


Expand All @@ -17,7 +15,7 @@


def is_truthy(x):
if isinstance(x, string_types):
if isinstance(x, str):
return x.lower() not in FALSEY_STRINGS
return bool(x)

Expand Down
7 changes: 3 additions & 4 deletions dynamic_rest/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""This module contains custom viewset classes."""
from django.core.exceptions import ObjectDoesNotExist
from django.http import QueryDict
import six
import json
from django.db import transaction, IntegrityError
from rest_framework import exceptions, status, viewsets
Expand Down Expand Up @@ -34,7 +33,7 @@ def __init__(self, query_params, *args, **kwargs):
else:
assert isinstance(
query_params,
(six.string_types, six.binary_type)
(str, bytes)
)
query_string = query_params
kwargs['mutable'] = True
Expand Down Expand Up @@ -461,7 +460,7 @@ def _validate_patch_all(self, data):
serializer = self.get_serializer()
fields = serializer.get_all_fields()
validated = {}
for name, value in six.iteritems(data):
for name, value in data.items():
field = fields.get(name, None)
if field is None:
raise ValidationError(
Expand Down Expand Up @@ -495,7 +494,7 @@ def _patch_all_loop(self, queryset, data):
try:
with transaction.atomic():
for record in queryset:
for k, v in six.iteritems(data):
for k, v in data.items():
setattr(record, k, v)
record.save()
updated += 1
Expand Down
1 change: 0 additions & 1 deletion install_requires.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ djangorestframework>=3.13,<3.16
inflection>=0.4.0
requests
hashids>=1.3.1
six>=1.16.0
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pytest-cov==3.0.0
pytest-django==4.5.2
pytest-sugar==0.9.5
pytest>=7.0.0
six==1.16.0
Sphinx==1.7.5
tox-pyenv==1.1.0
tox==3.25.1
Expand Down
7 changes: 3 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import django
from django.db import connection
from django.test import override_settings
import six
from rest_framework.test import APITestCase
from urllib.parse import quote

from tests.models import Cat, Group, Location, Permission, Profile, User
from tests.serializers import NestedEphemeralSerializer, PermissionSerializer
from tests.setup import create_fixture

UNICODE_STRING = six.unichr(9629) # unicode heart
UNICODE_STRING = chr(9629) # unicode heart
# UNICODE_URL_STRING = urllib.quote(UNICODE_STRING.encode('utf-8'))
UNICODE_URL_STRING = '%E2%96%9D'

Expand Down Expand Up @@ -353,7 +352,7 @@ def test_get_with_filter_unicode_no_match(self):
json.loads(response.content.decode('utf-8')))
with self.assertNumQueries(1):
response = self.client.get(
six.u('/users/?filter{name}[]=%s') % UNICODE_STRING
str('/users/?filter{name}[]=%s') % UNICODE_STRING
)
self.assertEqual(200, response.status_code)
self.assertEqual(
Expand All @@ -380,7 +379,7 @@ def test_get_with_filter_unicode(self):
)
with self.assertNumQueries(1):
response = self.client.get(
six.u('/users/?filter{name}[]=%s') % UNICODE_STRING
str('/users/?filter{name}[]=%s') % UNICODE_STRING
)
self.assertEqual(200, response.status_code)
self.assertEqual(
Expand Down
4 changes: 1 addition & 3 deletions tests/test_prefetch2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import six

from rest_framework.test import APITestCase

from dynamic_rest.prefetch import FastPrefetch, FastQuery
Expand Down Expand Up @@ -135,7 +133,7 @@ def test_m2o_prefetch(self):
self.assertTrue(
all(['user_set' in obj for obj in result])
)
location = six.next((
location = next((
o for o in result if o['user_set'] and len(o['user_set']) > 1
))

Expand Down
Loading