mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-06-28 17:33:10 +03:00
Import singledispatch straight from functools
This commit is contained in:
parent
ddacb9d4e8
commit
8356fccbdb
|
@ -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,
|
||||
|
@ -25,9 +26,6 @@ from graphql.pyutils import register_description
|
|||
|
||||
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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -4,7 +4,6 @@ from .utils import (
|
|||
camelize,
|
||||
get_model_fields,
|
||||
get_reverse_fields,
|
||||
import_single_dispatch,
|
||||
is_valid_django_model,
|
||||
maybe_queryset,
|
||||
)
|
||||
|
@ -16,6 +15,5 @@ __all__ = [
|
|||
"get_model_fields",
|
||||
"camelize",
|
||||
"is_valid_django_model",
|
||||
"import_single_dispatch",
|
||||
"GraphQLTestCase",
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user