Improved Python3 compat

This commit is contained in:
Syrus Akbary 2016-06-15 21:40:12 -07:00
parent 145183d0ae
commit ccfed3df3f
4 changed files with 12 additions and 11 deletions

View File

@ -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))

View File

@ -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

View File

@ -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

View File

@ -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']