Autolint all the files

This commit is contained in:
Syrus Akbary 2016-06-14 22:27:25 -07:00
parent 76ecd895e1
commit c74a75133e
40 changed files with 295 additions and 214 deletions

View File

@ -1,6 +1,5 @@
from ..data import setup
from ..schema import schema, Droid
from ..schema import Droid
def test_query_types():

View File

@ -1,5 +1,5 @@
import graphene
from graphene import implements, relay, resolve_only_args
from graphene import relay, resolve_only_args
from .data import create_ship, get_empire, get_faction, get_rebels, get_ship
@ -65,5 +65,4 @@ class Mutation(graphene.ObjectType):
introduce_ship = IntroduceShip.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)

View File

@ -14,4 +14,22 @@ from .types import (
)
from .utils.resolve_only_args import resolve_only_args
__all__ = ['ObjectType', 'InputObjectType', 'Interface', 'implements', 'Field', 'InputField', 'Schema', 'Scalar', 'String', 'ID', 'Int', 'Float', 'Enum', 'Boolean', 'List','NonNull', 'Argument','resolve_only_args']
__all__ = [
'ObjectType',
'InputObjectType',
'Interface',
'implements',
'Field',
'InputField',
'Schema',
'Scalar',
'String',
'ID',
'Int',
'Float',
'Enum',
'Boolean',
'List',
'NonNull',
'Argument',
'resolve_only_args']

View File

@ -1,3 +1,9 @@
from .node import Node
from .mutation import ClientIDMutation
from .connection import Connection
__all__ = [
'Node',
'ClientIDMutation',
'Connection',
]

View File

@ -1,23 +1,17 @@
import re
from collections import Iterable
import six
from graphql_relay import connection_definitions, connection_from_list
from ..types.field import Field
from ..types.objecttype import ObjectType, ObjectTypeMeta
from ..utils.props import props
from ..types.field import Field, InputField
from ..utils.get_fields import get_fields
from ..utils.copy_fields import copy_fields
from ..utils.props import props
from ..types.objecttype import ObjectType
from ..utils.is_base_type import is_base_type
from ..types.options import Options
from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type
from ..utils.props import props
class ConnectionMeta(ObjectTypeMeta):

View File

@ -1,19 +1,18 @@
from functools import partial
import six
from graphql_relay import mutation_with_client_mutation_id
from ..types.mutation import Mutation, MutationMeta
from ..types.inputobjecttype import InputObjectType
from ..types.field import Field, InputField
from ..utils.get_fields import get_fields
from ..utils.copy_fields import copy_fields
from ..utils.props import props
from ..types.inputobjecttype import InputObjectType
from ..types.mutation import Mutation, MutationMeta
from ..types.objecttype import ObjectType
from ..utils.is_base_type import is_base_type
from ..types.options import Options
from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type
from ..utils.props import props
class ClientIDMutationMeta(MutationMeta):
@ -41,7 +40,8 @@ class ClientIDMutationMeta(MutationMeta):
output_fields = copy_fields(Field, get_fields(ObjectType, attrs, bases))
mutate_and_get_payload = getattr(cls, 'mutate_and_get_payload', None)
assert mutate_and_get_payload, "{}.mutate_and_get_payload method is required in a ClientIDMutation ObjectType.".format(cls.__name__)
assert mutate_and_get_payload, "{}.mutate_and_get_payload method is required in a ClientIDMutation ObjectType.".format(
cls.__name__)
field = mutation_with_client_mutation_id(
name=options.name or cls.__name__,
@ -55,5 +55,6 @@ class ClientIDMutationMeta(MutationMeta):
class ClientIDMutation(six.with_metaclass(ClientIDMutationMeta, Mutation)):
class Meta:
abstract = True

View File

@ -1,11 +1,13 @@
from functools import partial
import six
from graphql_relay import node_definitions, from_global_id, to_global_id
from graphql_relay import from_global_id, node_definitions, to_global_id
from ..types.field import Field
from ..types.options import Options
from ..types.objecttype import ObjectTypeMeta
from ..types.interface import Interface
from ..types.objecttype import ObjectTypeMeta
from ..types.options import Options
class NodeMeta(ObjectTypeMeta):
@ -22,7 +24,12 @@ class NodeMeta(ObjectTypeMeta):
id_resolver=id_resolver,
)
cls._meta = Options(None, graphql_type=node_interface)
cls.Field = partial(Field.copy_and_extend, node_field, type=node_field.type, parent=cls, _creation_counter=None)
cls.Field = partial(
Field.copy_and_extend,
node_field,
type=node_field.type,
parent=cls,
_creation_counter=None)
else:
# The interface provided by node_definitions is not an instance
# of GrapheneInterfaceType, so it will have no graphql_type,
@ -71,6 +78,8 @@ class Node(six.with_metaclass(NodeMeta, Interface)):
in it
'''
if cls.require_get_node():
assert hasattr(object_type, 'get_node'), '{}.get_node method is required by the Node interface.'.format(object_type.__name__)
assert hasattr(
object_type, 'get_node'), '{}.get_node method is required by the Node interface.'.format(
object_type.__name__)
return super(Node, cls).implements(object_type)

View File

@ -1,10 +1,9 @@
import pytest
from ...types import ObjectType, Schema
from ...types.field import Field
from ...types.scalars import String
from ..connection import Connection
from ..node import Node
from ...types import ObjectType, Schema
from ...types.scalars import String
from ...types.field import Field
class MyObject(Node, ObjectType):
@ -16,6 +15,7 @@ class MyObject(Node, ObjectType):
class MyObjectConnection(Connection):
class Meta:
node = MyObject

View File

@ -1,13 +1,12 @@
import pytest
from graphql_relay import to_global_id
from ..mutation import ClientIDMutation
from ...types import ObjectType, Schema, implements
from ...types import ObjectType, Schema
from ...types.scalars import String
from ..mutation import ClientIDMutation
class SaySomething(ClientIDMutation):
class Input:
what = String()
phrase = String()
@ -33,7 +32,8 @@ def test_no_mutate_and_get_payload():
class MyMutation(ClientIDMutation):
pass
assert "MyMutation.mutate_and_get_payload method is required in a ClientIDMutation ObjectType." == str(excinfo.value)
assert "MyMutation.mutate_and_get_payload method is required in a ClientIDMutation ObjectType." == str(
excinfo.value)
def test_node_good():

View File

@ -2,9 +2,9 @@ import pytest
from graphql_relay import to_global_id
from ..node import Node
from ...types import ObjectType, Schema, implements
from ...types import ObjectType, Schema
from ...types.scalars import String
from ..node import Node
class MyNode(Node, ObjectType):
@ -59,6 +59,7 @@ def test_node_query_incorrect_id():
assert not executed.errors
assert executed.data == {'node': None}
def test_str_schema():
assert str(schema) == """
schema {

View File

@ -1,11 +1,12 @@
from graphql import graphql
from ...types import ObjectType, Schema
from ...types.scalars import Int, String
from ..node import Node
from ...types import ObjectType, Schema, implements
from ...types.scalars import String, Int
class CustomNode(Node):
@staticmethod
def to_global_id(type, id):
return id

View File

@ -8,4 +8,21 @@ from .field import Field, InputField
from .argument import Argument
from .inputobjecttype import InputObjectType
__all__ = ['ObjectType', 'InputObjectType', 'Interface', 'implements', 'Enum', 'Field', 'InputField', 'Schema', 'Scalar', 'String', 'ID', 'Int', 'Float', 'Boolean', 'List', 'NonNull', 'Argument']
__all__ = [
'ObjectType',
'InputObjectType',
'Interface',
'implements',
'Enum',
'Field',
'InputField',
'Schema',
'Scalar',
'String',
'ID',
'Int',
'Float',
'Boolean',
'List',
'NonNull',
'Argument']

View File

@ -1,6 +1,6 @@
import copy
from collections import OrderedDict
import inspect
from collections import OrderedDict
from itertools import chain
from graphql import GraphQLArgument

View File

@ -1,4 +1,5 @@
class GrapheneGraphQLType(object):
def __init__(self, *args, **kwargs):
self.graphene_type = kwargs.pop('graphene_type')
super(GrapheneGraphQLType, self).__init__(*args, **kwargs)

View File

@ -1,16 +1,19 @@
import six
from graphql.type import GraphQLEnumType, GraphQLEnumValue
from collections import OrderedDict
import six
from graphql.type import GraphQLEnumType, GraphQLEnumValue
from ..utils.is_base_type import is_base_type
from .definitions import GrapheneGraphQLType
from .options import Options
from ..utils.is_base_type import is_base_type
from .unmountedtype import UnmountedType
try:
from enum import Enum as PyEnum
except ImportError:
from ..utils.enum import Enum as PyEnum
from .unmountedtype import UnmountedType
class GrapheneEnumType(GrapheneGraphQLType, GraphQLEnumType):
@ -65,6 +68,7 @@ class EnumTypeMeta(type):
class Enum(six.with_metaclass(EnumTypeMeta, UnmountedType)):
@classmethod
def from_enum(cls, python_enum):
class Meta:

View File

@ -9,6 +9,7 @@ from .argument import to_arguments
class AbstractField(object):
@property
def name(self):
return self._name or self.attname and to_camel_case(self.attname)
@ -39,7 +40,8 @@ class AbstractField(object):
class Field(AbstractField, GraphQLField, OrderedType):
def __init__(self, type, args=None, resolver=None, source=None, deprecation_reason=None, name=None, description=None, required=False, _creation_counter=None, **extra_args):
def __init__(self, type, args=None, resolver=None, source=None, deprecation_reason=None,
name=None, description=None, required=False, _creation_counter=None, **extra_args):
self.name = name
self.attname = None
self.parent = None
@ -74,8 +76,7 @@ class Field(AbstractField, GraphQLField, OrderedType):
@property
def resolver(self):
from .objecttype import ObjectType
from .interface import GrapheneInterfaceType
pass
resolver = getattr(self.parent, 'resolve_{}'.format(self.attname), None)
@ -115,7 +116,9 @@ class Field(AbstractField, GraphQLField, OrderedType):
return self.copy_and_extend(self)
@classmethod
def copy_and_extend(cls, field, type=None, args=None, resolver=None, source=None, deprecation_reason=None, name=None, description=None, required=False, _creation_counter=False, parent=None, attname=None, **extra_args):
def copy_and_extend(
cls, field, type=None, args=None, resolver=None, source=None, deprecation_reason=None, name=None,
description=None, required=False, _creation_counter=False, parent=None, attname=None, **extra_args):
if isinstance(field, Field):
type = type or field._type
resolver = resolver or field._resolver
@ -185,7 +188,8 @@ class InputField(AbstractField, GraphQLInputObjectField, OrderedType):
return self.copy_and_extend(self)
@classmethod
def copy_and_extend(cls, field, type=None, default_value=None, description=None, name=None, required=False, parent=None, attname=None, _creation_counter=False):
def copy_and_extend(cls, field, type=None, default_value=None, description=None, name=None,
required=False, parent=None, attname=None, _creation_counter=False):
if isinstance(field, Field):
type = type or field._type
name = name or field._name

View File

@ -2,14 +2,14 @@ import six
from graphql import GraphQLInputObjectType
from .definitions import GrapheneGraphQLType
from .interface import attrs_without_fields
from .unmountedtype import UnmountedType
from .options import Options
from ..utils.is_base_type import is_base_type
from ..utils.get_fields import get_fields
from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type
from .definitions import GrapheneGraphQLType
from .field import InputField
from .interface import attrs_without_fields
from .options import Options
from .unmountedtype import UnmountedType
class GrapheneInputObjectType(GrapheneGraphQLType, GraphQLInputObjectType):

View File

@ -1,12 +1,13 @@
import six
from graphql import GraphQLInterfaceType
from .definitions import GrapheneGraphQLType
from .options import Options
from ..utils.is_base_type import is_base_type
from ..utils.get_fields import get_fields
from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type
from .definitions import GrapheneGraphQLType
from .field import Field
from .options import Options
class GrapheneInterfaceType(GrapheneGraphQLType, GraphQLInterfaceType):
@ -72,4 +73,3 @@ class Interface(six.with_metaclass(InterfaceTypeMeta)):
For example, if we want to check that the ObjectType have some required things
in it like Node.get_node
'''
pass

View File

@ -1,11 +1,11 @@
from functools import partial
import six
from .objecttype import ObjectTypeMeta, ObjectType
from .field import Field
from ..utils.props import props
from ..utils.is_base_type import is_base_type
from ..utils.props import props
from .field import Field
from .objecttype import ObjectType, ObjectTypeMeta
class MutationMeta(ObjectTypeMeta):

View File

@ -1,15 +1,17 @@
import copy
import six
from graphql import GraphQLObjectType
from .definitions import GrapheneGraphQLType
from .interface import GrapheneInterfaceType, InterfaceTypeMeta, Interface, attrs_without_fields
from .options import Options
from ..utils.is_base_type import is_base_type
from ..utils.get_fields import get_fields
from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type
from .definitions import GrapheneGraphQLType
from .field import Field
from .interface import (GrapheneInterfaceType, Interface, InterfaceTypeMeta,
attrs_without_fields)
from .options import Options
class GrapheneObjectType(GrapheneGraphQLType, GraphQLObjectType):
@ -120,6 +122,7 @@ def implements(*interfaces):
class ObjectType(six.with_metaclass(ObjectTypeMeta)):
def __init__(self, *args, **kwargs):
# GraphQL ObjectType acting as container
args_len = len(args)

View File

@ -1,10 +1,12 @@
import six
from graphql import GraphQLScalarType, GraphQLString, GraphQLInt, GraphQLFloat, GraphQLBoolean, GraphQLID
from .definitions import GrapheneGraphQLType
from .unmountedtype import UnmountedType
from .options import Options
from graphql import (GraphQLBoolean, GraphQLFloat, GraphQLID, GraphQLInt,
GraphQLScalarType, GraphQLString)
from ..utils.is_base_type import is_base_type
from .definitions import GrapheneGraphQLType
from .options import Options
from .unmountedtype import UnmountedType
class GrapheneScalarType(GrapheneGraphQLType, GraphQLScalarType):

View File

@ -1,9 +1,12 @@
from graphql import graphql, GraphQLSchema
from graphql import GraphQLSchema, graphql
from graphql.utils.introspection_query import introspection_query
from graphql.utils.schema_printer import print_schema
# from graphql.type.schema import assert_object_implements_interface
from ..utils.get_graphql_type import get_graphql_type
# from graphql.type.schema import assert_object_implements_interface
# from collections import defaultdict

View File

@ -6,6 +6,7 @@ from .unmountedtype import UnmountedType
class Structure(UnmountedType):
def __init__(self, of_type, *args, **kwargs):
super(Structure, self).__init__(*args, **kwargs)
self.of_type = of_type

View File

@ -1,7 +1,8 @@
import pytest
import copy
from graphql import GraphQLString, GraphQLArgument
import pytest
from graphql import GraphQLArgument, GraphQLString
from ..argument import Argument, to_arguments
from ..scalars import String

View File

@ -1,9 +1,9 @@
from graphql.type import GraphQLEnumType, GraphQLEnumValue
from ...utils.enum import Enum as PyEnum
from ..argument import Argument
from ..enum import Enum
from ..field import Field
from ..argument import Argument
from ...utils.enum import Enum as PyEnum
def test_enum_construction():

View File

@ -1,12 +1,12 @@
import pytest
import copy
from graphql import GraphQLString, GraphQLField, GraphQLInt, GraphQLNonNull
import pytest
from graphql import GraphQLField, GraphQLInt, GraphQLNonNull, GraphQLString
from ..field import Field
from ..argument import Argument
from ..objecttype import ObjectType
from ..scalars import String, Int
from ..field import Field
from ..scalars import Int, String
def test_field():

View File

@ -1,17 +1,14 @@
import pytest
from graphql import GraphQLObjectType, GraphQLField, GraphQLString, GraphQLInputObjectType
from graphql import GraphQLInputObjectType, GraphQLString
from ..objecttype import ObjectType
from ..field import InputField
from ..inputobjecttype import InputObjectType
from ..field import Field, InputField
from ..scalars import String
def test_generate_inputobjecttype():
class MyObjectType(InputObjectType):
'''Documentation'''
pass
graphql_type = MyObjectType._meta.graphql_type
assert isinstance(graphql_type, GraphQLInputObjectType)
@ -21,6 +18,7 @@ def test_generate_inputobjecttype():
def test_generate_inputobjecttype_with_meta():
class MyObjectType(InputObjectType):
class Meta:
name = 'MyOtherObjectType'
description = 'Documentation'

View File

@ -1,15 +1,14 @@
import pytest
from graphql import GraphQLInterfaceType, GraphQLField, GraphQLString, GraphQLInterfaceType
from graphql import GraphQLField, GraphQLInterfaceType, GraphQLString
from ..interface import Interface
from ..field import Field
from ..interface import Interface
def test_generate_interface():
class MyInterface(Interface):
'''Documentation'''
pass
graphql_type = MyInterface._meta.graphql_type
assert isinstance(graphql_type, GraphQLInterfaceType)
@ -19,6 +18,7 @@ def test_generate_interface():
def test_generate_interface_with_meta():
class MyInterface(Interface):
class Meta:
name = 'MyOtherInterface'
description = 'Documentation'

View File

@ -1,14 +1,11 @@
import pytest
from graphql import GraphQLObjectType, GraphQLField, GraphQLString, GraphQLInterfaceType
from graphql import GraphQLObjectType, GraphQLString
from ..schema import Schema
from ..objecttype import ObjectType
from ..mutation import Mutation
from ..interface import Interface
from ..scalars import String
from ..field import Field
from ..argument import Argument
from ..mutation import Mutation
from ..objecttype import ObjectType
from ..scalars import String
def test_generate_mutation_no_args():
@ -48,6 +45,7 @@ def test_generate_mutation_with_args():
def test_generate_mutation_with_meta():
class MyMutation(Mutation):
class Meta:
name = 'MyOtherMutation'
description = 'Documentation'
@ -64,6 +62,7 @@ def test_generate_mutation_with_meta():
def test_empty_mutation_has_meta():
class MyMutation(Mutation):
@classmethod
def mutate(cls, *args, **kwargs):
pass

View File

@ -1,12 +1,11 @@
import pytest
from graphql import GraphQLObjectType, GraphQLField, GraphQLString, GraphQLInterfaceType
from graphql import (GraphQLField, GraphQLInterfaceType, GraphQLObjectType,
GraphQLString)
from ..schema import Schema
from ..objecttype import ObjectType
from ..interface import Interface
from ..scalars import String
from ..field import Field
from ..interface import Interface
from ..objecttype import ObjectType
class Container(ObjectType):
@ -17,7 +16,6 @@ class Container(ObjectType):
def test_generate_objecttype():
class MyObjectType(ObjectType):
'''Documentation'''
pass
graphql_type = MyObjectType._meta.graphql_type
assert isinstance(graphql_type, GraphQLObjectType)
@ -27,6 +25,7 @@ def test_generate_objecttype():
def test_generate_objecttype_with_meta():
class MyObjectType(ObjectType):
class Meta:
name = 'MyOtherObjectType'
description = 'Documentation'
@ -139,6 +138,7 @@ def test_objecttype_reuse_graphql_type():
})
class GrapheneObjectType(ObjectType):
class Meta:
graphql_type = MyGraphQLType
@ -169,6 +169,7 @@ def test_objecttype_graphql_interface():
})
class GrapheneObjectType(ObjectType):
class Meta:
interfaces = [MyInterface]
@ -185,6 +186,7 @@ def test_objecttype_graphene_interface():
extended = Field(GraphQLString)
class GrapheneObjectType(ObjectType):
class Meta:
interfaces = [GrapheneInterface]

View File

@ -1,13 +1,15 @@
import pytest
from ..scalars import Scalar, String, Int, Float, Boolean
from graphene.utils.get_graphql_type import get_graphql_type
from graphql import GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLString
from ..field import Field
from ..objecttype import ObjectType
from graphql import GraphQLString, GraphQLInt, GraphQLFloat, GraphQLBoolean
from graphene.utils.get_graphql_type import get_graphql_type
from ..scalars import Boolean, Float, Int, Scalar, String
class DatetimeScalar(Scalar):
def serialize(value):
return value.isoformat()

View File

@ -1,9 +1,9 @@
from ..scalars import String
from ..field import Field
from ..objecttype import ObjectType
from ..interface import Interface
from ..structures import List
from ..objecttype import ObjectType
from ..scalars import String
from ..schema import Schema
from ..structures import List
class Character(Interface):
@ -18,6 +18,7 @@ class Pet(ObjectType):
# @implements(Character)
class Human(ObjectType):
class Meta:
interfaces = [Character]
@ -44,9 +45,11 @@ schema = Schema(query=RootQuery, types=[Human])
def test_schema():
executed = schema.execute('{ character {name, bestFriend { name }, friends { name}, ...on Human {pet { type } } } }')
executed = schema.execute(
'{ character {name, bestFriend { name }, friends { name}, ...on Human {pet { type } } } }')
assert not executed.errors
assert executed.data == {'character': {'name': 'Harry', 'bestFriend': {'name': 'Best'}, 'friends': [{'name': 'Peter'}], 'pet': {'type': 'Dog'}}}
assert executed.data == {'character': {'name': 'Harry', 'bestFriend': {
'name': 'Best'}, 'friends': [{'name': 'Peter'}], 'pet': {'type': 'Dog'}}}
def test_schema_introspect():

View File

@ -1,10 +1,9 @@
import pytest
from graphql import GraphQLString, GraphQLList, GraphQLNonNull
from graphql import GraphQLList, GraphQLNonNull, GraphQLString
from ..structures import List, NonNull
from ..scalars import String
from ..field import Field
from ..scalars import String
from ..structures import List, NonNull
def test_list():

View File

@ -1,6 +1,6 @@
from .field import Field, InputField
from .argument import Argument
from ..utils.orderedtype import OrderedType
from .argument import Argument
from .field import Field, InputField
# UnmountedType ?

View File

@ -1,5 +1,4 @@
from collections import OrderedDict
from ..types.field import Field, InputField
def copy_fields(like, fields, **extra):

View File

@ -35,6 +35,7 @@ except NameError:
# In Python 3 unicode no longer exists (it's just str)
unicode = str
class _RouteClassAttributeToGetattr(object):
"""Route attribute access on a class to __getattr__.
@ -44,6 +45,7 @@ class _RouteClassAttributeToGetattr(object):
class's __getattr__ method; this is done by raising AttributeError.
"""
def __init__(self, fget=None):
self.fget = fget
@ -85,6 +87,7 @@ def _is_sunder(name):
def _make_class_unpicklable(cls):
"""Make the given class un-picklable."""
def _break_on_call_reduce(self, protocol=None):
raise TypeError('%r cannot be pickled' % self)
cls.__reduce_ex__ = _break_on_call_reduce
@ -98,6 +101,7 @@ class _EnumDict(dict):
enumeration member names.
"""
def __init__(self):
super(_EnumDict, self).__init__()
self._member_names = []
@ -155,7 +159,7 @@ class EnumMeta(type):
# cannot be mixed with other types (int, float, etc.) if it has an
# inherited __new__ unless a new __new__ is defined (or the resulting
# class will fail).
if type(classdict) is dict:
if isinstance(classdict, dict):
original_dict = classdict
classdict = _EnumDict()
for k, v in original_dict.items():
@ -257,7 +261,6 @@ class EnumMeta(type):
except TypeError:
pass
# If a custom type is mixed into the Enum, and it does not know how
# to pickle itself, pickle.dumps will succeed but pickle.loads will
# fail. Rather than have the error show up later and possibly far
@ -277,12 +280,11 @@ class EnumMeta(type):
_make_class_unpicklable(enum_class)
unpicklable = True
# double check that repr and friends are not the mixin's or various
# things break (such as pickle)
for name in ('__repr__', '__str__', '__format__', '__reduce_ex__'):
class_method = getattr(enum_class, name)
obj_method = getattr(member_type, name, None)
getattr(member_type, name, None)
enum_method = getattr(first_enum, name, None)
if name not in classdict and class_method is not enum_method:
if name == '__reduce_ex__' and unpicklable:
@ -491,7 +493,6 @@ class EnumMeta(type):
if not bases or Enum is None:
return object, Enum
# double check that we are not subclassing a class with existing
# enumeration members; while we're at it, see if any other data
# type has been mixed in so we can use the correct __new__
@ -641,11 +642,12 @@ class EnumMeta(type):
temp_enum_dict = {}
temp_enum_dict['__doc__'] = "Generic enumeration.\n\n Derive from this class to define new enumerations.\n\n"
def __new__(cls, value):
# all enum instances are actually created during class construction
# without calling this method; this method is called by the metaclass'
# __call__ (i.e. Color(3) ), and by pickle
if type(value) is cls:
if isinstance(value, cls):
# For lookups like Color(Color.red)
value = value.value
# return value
@ -663,12 +665,14 @@ def __new__(cls, value):
temp_enum_dict['__new__'] = __new__
del __new__
def __repr__(self):
return "<%s.%s: %r>" % (
self.__class__.__name__, self._name_, self._value_)
temp_enum_dict['__repr__'] = __repr__
del __repr__
def __str__(self):
return "%s.%s" % (self.__class__.__name__, self._name_)
temp_enum_dict['__str__'] = __str__
@ -686,6 +690,7 @@ if pyver >= 3.0:
temp_enum_dict['__dir__'] = __dir__
del __dir__
def __format__(self, format_spec):
# mixed-in Enums should use the mixed-in type's __format__, otherwise
# we can get strange results with the Enum name showing up instead of
@ -710,7 +715,7 @@ del __format__
if pyver < 2.6:
def __cmp__(self, other):
if type(other) is self.__class__:
if isinstance(other, self.__class__):
if self is other:
return 0
return -1
@ -743,24 +748,27 @@ else:
def __eq__(self, other):
if type(other) is self.__class__:
if isinstance(other, self.__class__):
return self is other
return NotImplemented
temp_enum_dict['__eq__'] = __eq__
del __eq__
def __ne__(self, other):
if type(other) is self.__class__:
if isinstance(other, self.__class__):
return self is not other
return NotImplemented
temp_enum_dict['__ne__'] = __ne__
del __ne__
def __hash__(self):
return hash(self._name_)
temp_enum_dict['__hash__'] = __hash__
del __hash__
def __reduce_ex__(self, proto):
return self.__class__, (self._value_, )
temp_enum_dict['__reduce_ex__'] = __reduce_ex__
@ -773,18 +781,21 @@ del __reduce_ex__
# members are not set directly on the enum class -- __getattr__ is
# used to look them up.
@_RouteClassAttributeToGetattr
def name(self):
return self._name_
temp_enum_dict['name'] = name
del name
@_RouteClassAttributeToGetattr
def value(self):
return self._value_
temp_enum_dict['value'] = value
del value
@classmethod
def _convert(cls, name, module, filter, source=None):
"""
@ -815,12 +826,15 @@ del temp_enum_dict
# Enum has now been created
###########################
class IntEnum(int, Enum):
"""Enum where members are also (and must be) ints"""
def _reduce_ex_by_name(self, proto):
return self.name
def unique(enumeration):
"""Class decorator that ensures only unique members exist in an enumeration."""
duplicates = []

View File

@ -1,9 +1,9 @@
from collections import OrderedDict
from .get_graphql_type import get_graphql_type
from .is_graphene_type import is_graphene_type
from ..types.field import Field, InputField
from ..types.unmountedtype import UnmountedType
from .get_graphql_type import get_graphql_type
from .is_graphene_type import is_graphene_type
def get_fields_from_attrs(in_type, attrs):

View File

@ -1,8 +1,10 @@
from collections import OrderedDict
from graphql import GraphQLField, GraphQLString, GraphQLInterfaceType, GraphQLInt, GraphQLFloat
from ..get_fields import get_fields_from_attrs, get_fields_from_types
from ...types import Field, String, Argument, ObjectType
from graphql import (GraphQLField, GraphQLFloat, GraphQLInt,
GraphQLInterfaceType, GraphQLString)
from ...types import Argument, Field, ObjectType, String
from ..get_fields import get_fields_from_attrs, get_fields_from_types
def test_get_fields_from_attrs():

View File

@ -1,11 +1,10 @@
import pytest
from graphql.type.definition import is_type
from graphql import GraphQLObjectType, GraphQLField, GraphQLString
from graphene.types import ObjectType
from ..get_graphql_type import get_graphql_type
from graphql import GraphQLField, GraphQLObjectType, GraphQLString
from graphql.type.definition import is_type
from ..get_graphql_type import get_graphql_type
MyGraphQLType = GraphQLObjectType('MyGraphQLType', fields={
'field': GraphQLField(GraphQLString)
@ -21,6 +20,7 @@ def test_get_graphql_type_graphene():
def test_get_graphql_type_custom_graphene_type():
class MyGrapheneType(ObjectType):
class Meta:
graphql_type = MyGraphQLType

View File

@ -1,9 +1,8 @@
from graphql import GraphQLObjectType, GraphQLField, GraphQLString
from graphene.types import ObjectType
from graphql import GraphQLField, GraphQLObjectType, GraphQLString
from ..is_graphene_type import is_graphene_type
from graphene.types import ObjectType
def test_is_graphene_type_objecttype():
class MyObjectType(ObjectType):