Skip to content

Python 3 #904

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 8 commits into from
Apr 6, 2020
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
37 changes: 13 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ dist: xenial
install:
- pip install tox tox-travis

script:
script:
- tox

after_success:
after_success:
- pip install coveralls
- coveralls

Expand All @@ -24,24 +24,8 @@ jobs:
- env: DJANGO=master

include:
- python: 2.7
env: DJANGO=1.11

- python: 3.5
env: DJANGO=1.11
- python: 3.5
env: DJANGO=2.0
- python: 3.5
env: DJANGO=2.1
- python: 3.5
env: DJANGO=2.2

- python: 3.6
env: DJANGO=1.11
- python: 3.6
env: DJANGO=2.0
- python: 3.6
env: DJANGO=2.1
- python: 3.6
env: DJANGO=2.2
- python: 3.6
Expand All @@ -51,23 +35,28 @@ jobs:

- python: 3.7
env: DJANGO=1.11
- python: 3.7
env: DJANGO=2.0
- python: 3.7
env: DJANGO=2.1
- python: 3.7
env: DJANGO=2.2
- python: 3.7
env: DJANGO=3.0
- python: 3.7
env: DJANGO=master

- python: 3.7
- python: 3.8
env: DJANGO=1.11
- python: 3.8
env: DJANGO=2.2
- python: 3.8
env: DJANGO=3.0
- python: 3.8
env: DJANGO=master

- python: 3.8
env: TOXENV=black,flake8

- stage: deploy
script: skip
python: 3.7
python: 3.8
after_success: true
deploy:
provider: pypi
Expand Down
2 changes: 1 addition & 1 deletion docs/authorization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ For Django 2.0 and above:
path('graphql', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
]

.. _LoginRequiredMixin: https://docs.djangoproject.com/en/1.10/topics/auth/default/#the-loginrequired-mixin
.. _LoginRequiredMixin: https://docs.djangoproject.com/en/dev/topics/auth/default/#the-loginrequired-mixin
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@
master_doc = "index"

# General information about the project.
project = u"Graphene Django"
copyright = u"Graphene 2017"
author = u"Syrus Akbary"
project = "Graphene Django"
copyright = "Graphene 2017"
author = "Syrus Akbary"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u"1.0"
version = "1.0"
# The full version, including alpha/beta/rc tags.
release = u"1.0.dev"
release = "1.0.dev"

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

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

# If true, show URL addresses after external links.
Expand All @@ -334,7 +334,7 @@
(
master_doc,
"Graphene-Django",
u"Graphene Django Documentation",
"Graphene Django Documentation",
author,
"Graphene Django",
"One line description of project.",
Expand Down
3 changes: 1 addition & 2 deletions docs/filtering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ Filtering
=========

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

Expand Down
5 changes: 2 additions & 3 deletions graphene_django/converter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from collections import OrderedDict
from functools import singledispatch

from django.db import models
from django.utils.encoding import force_str
from django.utils.module_loading import import_string
Expand Down Expand Up @@ -26,9 +28,6 @@
from .settings import graphene_settings
from .compat import ArrayField, HStoreField, JSONField, RangeField
from .fields import DjangoListField, DjangoConnectionField
from .utils import import_single_dispatch

singledispatch = import_single_dispatch()


def convert_choice_name(name):
Expand Down
3 changes: 1 addition & 2 deletions graphene_django/debug/sql/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from threading import local
from time import time

import six
from django.utils.encoding import force_str

from .types import DjangoDebugSQL
Expand Down Expand Up @@ -77,7 +76,7 @@ def __init__(self, cursor, db, logger):
self.logger = logger

def _quote_expr(self, element):
if isinstance(element, six.string_types):
if isinstance(element, str):
return "'%s'" % force_str(element).replace("'", "''")
else:
return repr(element)
Expand Down
1 change: 0 additions & 1 deletion graphene_django/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from functools import partial

import six
from django.db.models.query import QuerySet
from graphql_relay.connection.arrayconnection import connection_from_list_slice
from promise import Promise
Expand Down
32 changes: 1 addition & 31 deletions graphene_django/filter/filterset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import itertools

from django.db import models
from django_filters import Filter, MultipleChoiceFilter, VERSION
from django_filters import Filter, MultipleChoiceFilter
from django_filters.filterset import BaseFilterSet, FilterSet
from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS

Expand Down Expand Up @@ -50,36 +50,6 @@ class GrapheneFilterSetMixin(BaseFilterSet):
)


# To support a Django 1.11 + Python 2.7 combination django-filter must be
# < 2.x.x. To support the earlier version of django-filter, the
# filter_for_reverse_field method must be present on GrapheneFilterSetMixin and
# must not be present for later versions of django-filter.
if VERSION[0] < 2:
from django.utils.text import capfirst

class GrapheneFilterSetMixinPython2(GrapheneFilterSetMixin):
@classmethod
def filter_for_reverse_field(cls, f, name):
"""Handles retrieving filters for reverse relationships
We override the default implementation so that we can handle
Global IDs (the default implementation expects database
primary keys)
"""
try:
rel = f.field.remote_field
except AttributeError:
rel = f.field.rel
default = {"name": name, "label": capfirst(rel.related_name)}
if rel.multiple:
# For to-many relationships
return GlobalIDMultipleChoiceFilter(**default)
else:
# For to-one relationships
return GlobalIDFilter(**default)

GrapheneFilterSetMixin = GrapheneFilterSetMixinPython2


def setup_filterset(filterset_class):
""" Wrap a provided filterset in Graphene-specific functionality
"""
Expand Down
4 changes: 1 addition & 3 deletions graphene_django/filter/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import six

from django_filters.utils import get_model_field
from .filterset import custom_filterset_factory, setup_filterset

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

args = {}
model = filterset_class._meta.model
for name, filter_field in six.iteritems(filterset_class.base_filters):
for name, filter_field in filterset_class.base_filters.items():
form_field = None

if name in filterset_class.declared_filters:
Expand Down
6 changes: 2 additions & 4 deletions graphene_django/forms/converter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from functools import singledispatch

from django import forms
from django.core.exceptions import ImproperlyConfigured

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

from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField
from ..utils import import_single_dispatch


singledispatch = import_single_dispatch()


@singledispatch
Expand Down
5 changes: 2 additions & 3 deletions graphene_django/rest_framework/serializer_converter.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from functools import singledispatch

from django.core.exceptions import ImproperlyConfigured
from rest_framework import serializers

import graphene

from ..registry import get_global_registry
from ..converter import convert_choices_to_named_enum_with_descriptions
from ..utils import import_single_dispatch
from .types import DictType

singledispatch = import_single_dispatch()


@singledispatch
def get_graphene_type_from_serializer_field(field):
Expand Down
3 changes: 1 addition & 2 deletions graphene_django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""
from __future__ import unicode_literals

import six
from django.conf import settings
from django.test.signals import setting_changed

Expand Down Expand Up @@ -55,7 +54,7 @@ def perform_import(val, setting_name):
"""
if val is None:
return None
elif isinstance(val, six.string_types):
elif isinstance(val, str):
return import_from_string(val, setting_name)
elif isinstance(val, (list, tuple)):
return [import_from_string(item, setting_name) for item in val]
Expand Down
6 changes: 3 additions & 3 deletions graphene_django/tests/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

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

Expand Down Expand Up @@ -46,7 +46,7 @@ class Reporter(models.Model):
"Reporter Type",
null=True,
blank=True,
choices=[(1, u"Regular"), (2, u"CNN Reporter")],
choices=[(1, "Regular"), (2, "CNN Reporter")],
)

def __str__(self): # __unicode__ on Python 2
Expand Down Expand Up @@ -105,7 +105,7 @@ class Article(models.Model):
"Importance",
null=True,
blank=True,
choices=[(1, u"Very important"), (2, u"Not as important")],
choices=[(1, "Very important"), (2, "Not as important")],
)

def __str__(self): # __unicode__ on Python 2
Expand Down
2 changes: 1 addition & 1 deletion graphene_django/tests/test_command.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from textwrap import dedent

from django.core import management
from io import StringIO
from mock import mock_open, patch
from six import StringIO

from graphene import ObjectType, Schema, String

Expand Down
2 changes: 1 addition & 1 deletion graphene_django/tests/test_converter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from collections import namedtuple
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from graphene import NonNull
from py.test import raises

Expand Down
5 changes: 1 addition & 4 deletions graphene_django/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings
from collections import OrderedDict
from typing import Type

import six
from django.db.models import Model
from django.utils.functional import SimpleLazyObject

Expand All @@ -21,9 +21,6 @@
is_valid_django_model,
)

if six.PY3:
from typing import Type


ALL_FIELDS = "__all__"

Expand Down
2 changes: 0 additions & 2 deletions graphene_django/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
camelize,
get_model_fields,
get_reverse_fields,
import_single_dispatch,
is_valid_django_model,
maybe_queryset,
)
Expand All @@ -16,6 +15,5 @@
"get_model_fields",
"camelize",
"is_valid_django_model",
"import_single_dispatch",
"GraphQLTestCase",
]
Loading