Skip to content

Commit

Permalink
Import singledispatch straight from functools
Browse files Browse the repository at this point in the history
  • Loading branch information
ktosiek committed Sep 16, 2019
1 parent ddacb9d commit 8356fcc
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 35 deletions.
4 changes: 1 addition & 3 deletions graphene_django/converter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.utils.encoding import force_text
from django.utils.functional import Promise
from functools import singledispatch

from graphene import (
ID,
Expand All @@ -25,9 +26,6 @@

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
5 changes: 1 addition & 4 deletions graphene_django/forms/converter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from django import forms
from django.core.exceptions import ImproperlyConfigured
from functools import singledispatch

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
3 changes: 1 addition & 2 deletions graphene_django/rest_framework/serializer_converter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from django.core.exceptions import ImproperlyConfigured
from rest_framework import serializers
from functools import singledispatch

import graphene

from ..registry import get_global_registry
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
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",
]
23 changes: 0 additions & 23 deletions graphene_django/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,3 @@ def get_model_fields(model):

def is_valid_django_model(model):
return inspect.isclass(model) and issubclass(model, models.Model)


def import_single_dispatch():
try:
from functools import singledispatch
except ImportError:
singledispatch = None

if not singledispatch:
try:
from singledispatch import singledispatch
except ImportError:
pass

if not singledispatch:
raise Exception(
"It seems your python version does not include "
"functools.singledispatch. Please install the 'singledispatch' "
"package. More information here: "
"https://pypi.python.org/pypi/singledispatch"
)

return singledispatch
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"graphene>=3.0.dev,<4",
"graphql-core>=3.0.0b0,<4",
"Django>=1.11",
"singledispatch>=3.4.0.3",
"promise>=2.1",
],
setup_requires=["pytest-runner"],
Expand Down

0 comments on commit 8356fcc

Please sign in to comment.