Skip to content

Commit dd0d6ef

Browse files
authored
Python 3 (#904)
* Remove Python 2 support * Upgrade Python & Django versions * Remove unsupported Django versions * Remove unsupported Python versions * Add Python 3.8 * Drop support for django-filter < 2 * Update LoginRequiredMixin doc link * Remove redundant import * Resolve RemovedInDjango40Warning warnings * gql/graphene-django/graphene_django/tests/test_converter.py:175: RemovedInDjango40Warning: django.utils.translation.ugettext_lazy() is deprecated in favor of django.utils.translation.gettext_lazy(). * graphene-django/graphene_django/utils/utils.py:28: RemovedInDjango40Warning: force_text() is deprecated in favor of force_str(). * No need to use unicode strings with Python3 * Remove singledispatch dependency singledispatch is inluded with Python >= 3.4, no need for external package.
1 parent b84f61a commit dd0d6ef

21 files changed

+53
-145
lines changed

.travis.yml

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ dist: xenial
55
install:
66
- pip install tox tox-travis
77

8-
script:
8+
script:
99
- tox
1010

11-
after_success:
11+
after_success:
1212
- pip install coveralls
1313
- coveralls
1414

@@ -24,24 +24,8 @@ jobs:
2424
- env: DJANGO=master
2525

2626
include:
27-
- python: 2.7
28-
env: DJANGO=1.11
29-
30-
- python: 3.5
31-
env: DJANGO=1.11
32-
- python: 3.5
33-
env: DJANGO=2.0
34-
- python: 3.5
35-
env: DJANGO=2.1
36-
- python: 3.5
37-
env: DJANGO=2.2
38-
3927
- python: 3.6
4028
env: DJANGO=1.11
41-
- python: 3.6
42-
env: DJANGO=2.0
43-
- python: 3.6
44-
env: DJANGO=2.1
4529
- python: 3.6
4630
env: DJANGO=2.2
4731
- python: 3.6
@@ -51,23 +35,28 @@ jobs:
5135

5236
- python: 3.7
5337
env: DJANGO=1.11
54-
- python: 3.7
55-
env: DJANGO=2.0
56-
- python: 3.7
57-
env: DJANGO=2.1
5838
- python: 3.7
5939
env: DJANGO=2.2
6040
- python: 3.7
6141
env: DJANGO=3.0
6242
- python: 3.7
6343
env: DJANGO=master
6444

65-
- python: 3.7
45+
- python: 3.8
46+
env: DJANGO=1.11
47+
- python: 3.8
48+
env: DJANGO=2.2
49+
- python: 3.8
50+
env: DJANGO=3.0
51+
- python: 3.8
52+
env: DJANGO=master
53+
54+
- python: 3.8
6655
env: TOXENV=black,flake8
6756

6857
- stage: deploy
6958
script: skip
70-
python: 3.7
59+
python: 3.8
7160
after_success: true
7261
deploy:
7362
provider: pypi

docs/authorization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,4 @@ For Django 2.0 and above:
184184
path('graphql', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
185185
]
186186
187-
.. _LoginRequiredMixin: https://docs.djangoproject.com/en/1.10/topics/auth/default/#the-loginrequired-mixin
187+
.. _LoginRequiredMixin: https://docs.djangoproject.com/en/dev/topics/auth/default/#the-loginrequired-mixin

docs/conf.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@
6060
master_doc = "index"
6161

6262
# General information about the project.
63-
project = u"Graphene Django"
64-
copyright = u"Graphene 2017"
65-
author = u"Syrus Akbary"
63+
project = "Graphene Django"
64+
copyright = "Graphene 2017"
65+
author = "Syrus Akbary"
6666

6767
# The version info for the project you're documenting, acts as replacement for
6868
# |version| and |release|, also used in various other places throughout the
6969
# built documents.
7070
#
7171
# The short X.Y version.
72-
version = u"1.0"
72+
version = "1.0"
7373
# The full version, including alpha/beta/rc tags.
74-
release = u"1.0.dev"
74+
release = "1.0.dev"
7575

7676
# The language for content autogenerated by Sphinx. Refer to documentation
7777
# for a list of supported languages.
@@ -276,7 +276,7 @@
276276
# (source start file, target name, title,
277277
# author, documentclass [howto, manual, or own class]).
278278
latex_documents = [
279-
(master_doc, "Graphene.tex", u"Graphene Documentation", u"Syrus Akbary", "manual")
279+
(master_doc, "Graphene.tex", "Graphene Documentation", "Syrus Akbary", "manual")
280280
]
281281

282282
# The name of an image file (relative to this directory) to place at the top of
@@ -317,7 +317,7 @@
317317
# One entry per manual page. List of tuples
318318
# (source start file, name, description, authors, manual section).
319319
man_pages = [
320-
(master_doc, "graphene_django", u"Graphene Django Documentation", [author], 1)
320+
(master_doc, "graphene_django", "Graphene Django Documentation", [author], 1)
321321
]
322322

323323
# If true, show URL addresses after external links.
@@ -334,7 +334,7 @@
334334
(
335335
master_doc,
336336
"Graphene-Django",
337-
u"Graphene Django Documentation",
337+
"Graphene Django Documentation",
338338
author,
339339
"Graphene Django",
340340
"One line description of project.",

docs/filtering.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Filtering
22
=========
33

44
Graphene integrates with
5-
`django-filter <https://django-filter.readthedocs.io/en/master/>`__ (2.x for
6-
Python 3 or 1.x for Python 2) to provide filtering of results. See the `usage
5+
`django-filter <https://django-filter.readthedocs.io/en/master/>`__ to provide filtering of results. See the `usage
76
documentation <https://django-filter.readthedocs.io/en/master/guide/usage.html#the-filter>`__
87
for details on the format for ``filter_fields``.
98

graphene_django/converter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from collections import OrderedDict
2+
from functools import singledispatch
3+
24
from django.db import models
35
from django.utils.encoding import force_str
46
from django.utils.module_loading import import_string
@@ -26,9 +28,6 @@
2628
from .settings import graphene_settings
2729
from .compat import ArrayField, HStoreField, JSONField, RangeField
2830
from .fields import DjangoListField, DjangoConnectionField
29-
from .utils import import_single_dispatch
30-
31-
singledispatch = import_single_dispatch()
3231

3332

3433
def convert_choice_name(name):

graphene_django/debug/sql/tracking.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from threading import local
66
from time import time
77

8-
import six
98
from django.utils.encoding import force_str
109

1110
from .types import DjangoDebugSQL
@@ -77,7 +76,7 @@ def __init__(self, cursor, db, logger):
7776
self.logger = logger
7877

7978
def _quote_expr(self, element):
80-
if isinstance(element, six.string_types):
79+
if isinstance(element, str):
8180
return "'%s'" % force_str(element).replace("'", "''")
8281
else:
8382
return repr(element)

graphene_django/fields.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from functools import partial
22

3-
import six
43
from django.db.models.query import QuerySet
54
from graphql_relay.connection.arrayconnection import connection_from_list_slice
65
from promise import Promise

graphene_django/filter/filterset.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import itertools
22

33
from django.db import models
4-
from django_filters import Filter, MultipleChoiceFilter, VERSION
4+
from django_filters import Filter, MultipleChoiceFilter
55
from django_filters.filterset import BaseFilterSet, FilterSet
66
from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS
77

@@ -50,36 +50,6 @@ class GrapheneFilterSetMixin(BaseFilterSet):
5050
)
5151

5252

53-
# To support a Django 1.11 + Python 2.7 combination django-filter must be
54-
# < 2.x.x. To support the earlier version of django-filter, the
55-
# filter_for_reverse_field method must be present on GrapheneFilterSetMixin and
56-
# must not be present for later versions of django-filter.
57-
if VERSION[0] < 2:
58-
from django.utils.text import capfirst
59-
60-
class GrapheneFilterSetMixinPython2(GrapheneFilterSetMixin):
61-
@classmethod
62-
def filter_for_reverse_field(cls, f, name):
63-
"""Handles retrieving filters for reverse relationships
64-
We override the default implementation so that we can handle
65-
Global IDs (the default implementation expects database
66-
primary keys)
67-
"""
68-
try:
69-
rel = f.field.remote_field
70-
except AttributeError:
71-
rel = f.field.rel
72-
default = {"name": name, "label": capfirst(rel.related_name)}
73-
if rel.multiple:
74-
# For to-many relationships
75-
return GlobalIDMultipleChoiceFilter(**default)
76-
else:
77-
# For to-one relationships
78-
return GlobalIDFilter(**default)
79-
80-
GrapheneFilterSetMixin = GrapheneFilterSetMixinPython2
81-
82-
8353
def setup_filterset(filterset_class):
8454
""" Wrap a provided filterset in Graphene-specific functionality
8555
"""

graphene_django/filter/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import six
2-
31
from django_filters.utils import get_model_field
42
from .filterset import custom_filterset_factory, setup_filterset
53

@@ -13,7 +11,7 @@ def get_filtering_args_from_filterset(filterset_class, type):
1311

1412
args = {}
1513
model = filterset_class._meta.model
16-
for name, filter_field in six.iteritems(filterset_class.base_filters):
14+
for name, filter_field in filterset_class.base_filters.items():
1715
form_field = None
1816

1917
if name in filterset_class.declared_filters:

graphene_django/forms/converter.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
from functools import singledispatch
2+
13
from django import forms
24
from django.core.exceptions import ImproperlyConfigured
35

46
from graphene import ID, Boolean, Float, Int, List, String, UUID, Date, DateTime, Time
57

68
from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField
7-
from ..utils import import_single_dispatch
8-
9-
10-
singledispatch = import_single_dispatch()
119

1210

1311
@singledispatch

graphene_django/rest_framework/serializer_converter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
from functools import singledispatch
2+
13
from django.core.exceptions import ImproperlyConfigured
24
from rest_framework import serializers
35

46
import graphene
57

68
from ..registry import get_global_registry
79
from ..converter import convert_choices_to_named_enum_with_descriptions
8-
from ..utils import import_single_dispatch
910
from .types import DictType
1011

11-
singledispatch = import_single_dispatch()
12-
1312

1413
@singledispatch
1514
def get_graphene_type_from_serializer_field(field):

graphene_django/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"""
1414
from __future__ import unicode_literals
1515

16-
import six
1716
from django.conf import settings
1817
from django.test.signals import setting_changed
1918

@@ -55,7 +54,7 @@ def perform_import(val, setting_name):
5554
"""
5655
if val is None:
5756
return None
58-
elif isinstance(val, six.string_types):
57+
elif isinstance(val, str):
5958
return import_from_string(val, setting_name)
6059
elif isinstance(val, (list, tuple)):
6160
return [import_from_string(item, setting_name) for item in val]

graphene_django/tests/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import absolute_import
22

33
from django.db import models
4-
from django.utils.translation import ugettext_lazy as _
4+
from django.utils.translation import gettext_lazy as _
55

66
CHOICES = ((1, "this"), (2, _("that")))
77

@@ -46,7 +46,7 @@ class Reporter(models.Model):
4646
"Reporter Type",
4747
null=True,
4848
blank=True,
49-
choices=[(1, u"Regular"), (2, u"CNN Reporter")],
49+
choices=[(1, "Regular"), (2, "CNN Reporter")],
5050
)
5151

5252
def __str__(self): # __unicode__ on Python 2
@@ -105,7 +105,7 @@ class Article(models.Model):
105105
"Importance",
106106
null=True,
107107
blank=True,
108-
choices=[(1, u"Very important"), (2, u"Not as important")],
108+
choices=[(1, "Very important"), (2, "Not as important")],
109109
)
110110

111111
def __str__(self): # __unicode__ on Python 2

graphene_django/tests/test_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from textwrap import dedent
22

33
from django.core import management
4+
from io import StringIO
45
from mock import mock_open, patch
5-
from six import StringIO
66

77
from graphene import ObjectType, Schema, String
88

graphene_django/tests/test_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from collections import namedtuple
33
from django.db import models
4-
from django.utils.translation import ugettext_lazy as _
4+
from django.utils.translation import gettext_lazy as _
55
from graphene import NonNull
66
from py.test import raises
77

graphene_django/types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import warnings
22
from collections import OrderedDict
3+
from typing import Type
34

4-
import six
55
from django.db.models import Model
66
from django.utils.functional import SimpleLazyObject
77

@@ -21,9 +21,6 @@
2121
is_valid_django_model,
2222
)
2323

24-
if six.PY3:
25-
from typing import Type
26-
2724

2825
ALL_FIELDS = "__all__"
2926

graphene_django/utils/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
camelize,
55
get_model_fields,
66
get_reverse_fields,
7-
import_single_dispatch,
87
is_valid_django_model,
98
maybe_queryset,
109
)
@@ -16,6 +15,5 @@
1615
"get_model_fields",
1716
"camelize",
1817
"is_valid_django_model",
19-
"import_single_dispatch",
2018
"GraphQLTestCase",
2119
]

0 commit comments

Comments
 (0)