From ccfed3df3fddc5622cbbdcd5c95e5e8285613dbb Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Wed, 15 Jun 2016 21:40:12 -0700 Subject: [PATCH] Improved Python3 compat --- graphene/types/enum.py | 4 +++- graphene/types/field.py | 2 +- graphene/types/tests/test_enum.py | 3 +-- graphene/utils/tests/test_get_fields.py | 14 +++++++------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/graphene/types/enum.py b/graphene/types/enum.py index 5f2d4452..aa02fbde 100644 --- a/graphene/types/enum.py +++ b/graphene/types/enum.py @@ -15,7 +15,6 @@ except ImportError: from ..utils.enum import Enum as PyEnum - class GrapheneEnumType(GrapheneGraphQLType, GraphQLEnumType): pass @@ -61,6 +60,9 @@ class EnumTypeMeta(type): return cls + def __prepare__(name, bases, **kwargs): + return OrderedDict() + def __call__(cls, *args, **kwargs): if cls is Enum: return cls.from_enum(PyEnum(*args, **kwargs)) diff --git a/graphene/types/field.py b/graphene/types/field.py index fc6fcad6..b9aa285a 100644 --- a/graphene/types/field.py +++ b/graphene/types/field.py @@ -95,7 +95,7 @@ class Field(AbstractField, GraphQLField, OrderedType): # break if resolver: - resolver = resolver.__func__ + resolver = getattr(resolver, '__func__', resolver) else: resolver = self.default_resolver diff --git a/graphene/types/tests/test_enum.py b/graphene/types/tests/test_enum.py index af7c4a9e..4e26e12f 100644 --- a/graphene/types/tests/test_enum.py +++ b/graphene/types/tests/test_enum.py @@ -1,8 +1,7 @@ from graphql.type import GraphQLEnumType, GraphQLEnumValue -from ...utils.enum import Enum as PyEnum from ..argument import Argument -from ..enum import Enum +from ..enum import Enum, PyEnum from ..field import Field diff --git a/graphene/utils/tests/test_get_fields.py b/graphene/utils/tests/test_get_fields.py index 342b582c..0c188e75 100644 --- a/graphene/utils/tests/test_get_fields.py +++ b/graphene/utils/tests/test_get_fields.py @@ -8,13 +8,13 @@ from ..get_fields import get_fields_from_attrs, get_fields_from_types def test_get_fields_from_attrs(): - attrs = { - 'field_string': Field(String), - 'string': String(), - 'other': None, - 'argument': Argument(String), - 'graphql_field': GraphQLField(GraphQLString) - } + attrs = OrderedDict(( + ('field_string', Field(String)), + ('string', String()), + ('other', None), + ('argument', Argument(String)), + ('graphql_field', GraphQLField(GraphQLString)), + )) extracted_fields = OrderedDict(get_fields_from_attrs(ObjectType, attrs)) assert [f for f in extracted_fields.keys()] == ['field_string', 'string']