diff --git a/graphene/pyutils/version.py b/graphene/pyutils/version.py index 633f4429..ab177e12 100644 --- a/graphene/pyutils/version.py +++ b/graphene/pyutils/version.py @@ -45,13 +45,9 @@ def get_complete_version(version=None): from graphene import VERSION as version else: if len(version) is not 5: - raise AssertionError( - "Version needs to be 5" - ) - if version[3] not in ('alpha', 'beta', 'rc', 'final'): - raise AssertionError( - "Release version is unkown" - ) + raise AssertionError("Version needs to be 5") + if version[3] not in ("alpha", "beta", "rc", "final"): + raise AssertionError("Release version is unkown") return version diff --git a/graphene/relay/connection.py b/graphene/relay/connection.py index 65d4dae2..3f58fdbf 100644 --- a/graphene/relay/connection.py +++ b/graphene/relay/connection.py @@ -48,14 +48,14 @@ class Connection(ObjectType): _meta = ConnectionOptions(cls) if not node: raise AssertionError( - "You have to provide a node in {}.Meta" - .format(cls.__name__) + "You have to provide a node in {}.Meta".format(cls.__name__) ) if not issubclass(node, (Scalar, Enum, ObjectType, Interface, Union, NonNull)): raise AssertionError( - 'Received incompatible node "{}" for Connection {}.' - .format(node, cls.__name__) + 'Received incompatible node "{}" for Connection {}.'.format( + node, cls.__name__ + ) ) base_name = re.sub("Connection$", "", name or cls.__name__) or node._meta.name @@ -114,8 +114,9 @@ class IterableConnectionField(Field): if not issubclass(connection_type, Connection): raise AssertionError( - '{} type have to be a subclass of Connection. Received "{}".' - .format(self.__class__.__name__, connection_type) + '{} type have to be a subclass of Connection. Received "{}".'.format( + self.__class__.__name__, connection_type + ) ) return type @@ -126,11 +127,12 @@ class IterableConnectionField(Field): if not isinstance(resolved, Iterable): raise AssertionError( - ''' + """ Resolved value from the connection field have to be iterable or instance of {}. Received "{}" - ''' - .format(connection_type, resolved) + """.format( + connection_type, resolved + ) ) connection = connection_from_list( resolved, diff --git a/graphene/relay/mutation.py b/graphene/relay/mutation.py index 72166317..211ee44f 100644 --- a/graphene/relay/mutation.py +++ b/graphene/relay/mutation.py @@ -47,8 +47,9 @@ class ClientIDMutation(Mutation): if cls.mutate and cls.mutate.__func__ == ClientIDMutation.mutate.__func__: if not mutate_and_get_payload: raise AssertionError( - "{name}.mutate_and_get_payload method is required in a ClientIDMutation." - .format(name=name or cls.__name__) + "{name}.mutate_and_get_payload method is required in a ClientIDMutation.".format( + name=name or cls.__name__ + ) ) if not name: diff --git a/graphene/relay/node.py b/graphene/relay/node.py index 6a4348a6..44020ae3 100644 --- a/graphene/relay/node.py +++ b/graphene/relay/node.py @@ -48,11 +48,9 @@ class GlobalID(Field): class NodeField(Field): - - def __init__(self, node, type=False, deprecation_reason=None, - name=None, **kwargs): + def __init__(self, node, type=False, deprecation_reason=None, name=None, **kwargs): if not issubclass(node, Node): - raise AssertionError('NodeField can only operate in Nodes') + raise AssertionError("NodeField can only operate in Nodes") self.node_type = node self.field_type = type @@ -103,8 +101,7 @@ class Node(AbstractNode): if only_type: if graphene_type != only_type: raise AssertionError( - 'Must receive a {} id.' - .format(only_type._meta.name) + "Must receive a {} id.".format(only_type._meta.name) ) # We make sure the ObjectType implements the "Node" interface diff --git a/graphene/types/argument.py b/graphene/types/argument.py index ebcd9caf..326e173d 100644 --- a/graphene/types/argument.py +++ b/graphene/types/argument.py @@ -75,8 +75,7 @@ def to_arguments(args, extra_args=None): arg_name = default_name or arg.name if arg_name in arguments: raise AssertionError( - 'More than one Argument have same name "{}".' - .format(arg_name) + 'More than one Argument have same name "{}".'.format(arg_name) ) arguments[arg_name] = arg diff --git a/graphene/types/datetime.py b/graphene/types/datetime.py index bf294176..3aa38c98 100644 --- a/graphene/types/datetime.py +++ b/graphene/types/datetime.py @@ -20,10 +20,7 @@ class Date(Scalar): if isinstance(date, datetime.datetime): date = date.date() if not isinstance(date, datetime.date): - raise AssertionError( - 'Received not compatible date "{}"' - .format(repr(date)) - ) + raise AssertionError('Received not compatible date "{}"'.format(repr(date))) return date.isoformat() @classmethod @@ -50,8 +47,7 @@ class DateTime(Scalar): def serialize(dt): if not isinstance(dt, (datetime.datetime, datetime.date)): raise AssertionError( - 'Received not compatible datetime "{}"' - .format(repr(dt)) + 'Received not compatible datetime "{}"'.format(repr(dt)) ) return dt.isoformat() @@ -78,10 +74,7 @@ class Time(Scalar): @staticmethod def serialize(time): if not isinstance(time, datetime.time): - raise AssertionError( - 'Received not compatible time "{}"' - .format(repr(time)) - ) + raise AssertionError('Received not compatible time "{}"'.format(repr(time))) return time.isoformat() @classmethod diff --git a/graphene/types/dynamic.py b/graphene/types/dynamic.py index ef421b49..d7747644 100644 --- a/graphene/types/dynamic.py +++ b/graphene/types/dynamic.py @@ -14,7 +14,7 @@ class Dynamic(MountedType): super(Dynamic, self).__init__(_creation_counter=_creation_counter) if not (inspect.isfunction(type) or isinstance(type, partial)): raise AssertionError( - 'type is expected to be a function or an instance of partial' + "type is expected to be a function or an instance of partial" ) self.type = type self.with_schema = with_schema diff --git a/graphene/types/field.py b/graphene/types/field.py index 48025913..a42d131a 100644 --- a/graphene/types/field.py +++ b/graphene/types/field.py @@ -37,17 +37,17 @@ class Field(MountedType): if args and not isinstance(args, Mapping): raise AssertionError( - 'Arguments in a field have to be a mapping, received "{}".' - .format(args) + 'Arguments in a field have to be a mapping, received "{}".'.format(args) ) if source and resolver: raise AssertionError( - 'A Field cannot have a source and a resolver in at the same time.' + "A Field cannot have a source and a resolver in at the same time." ) if callable(default_value): raise AssertionError( - 'The default value can not be a function but received "{}".' - .format(base_type(default_value)) + 'The default value can not be a function but received "{}".'.format( + base_type(default_value) + ) ) if required: diff --git a/graphene/types/mountedtype.py b/graphene/types/mountedtype.py index d6002a72..fc4efb85 100644 --- a/graphene/types/mountedtype.py +++ b/graphene/types/mountedtype.py @@ -10,9 +10,8 @@ class MountedType(OrderedType): """ if not isinstance(unmounted, UnmountedType): raise AssertionError( - "{} can't mount {}" - .format(cls.__name__, repr(unmounted)) - ) + "{} can't mount {}".format(cls.__name__, repr(unmounted)) + ) return cls( unmounted.get_type(), diff --git a/graphene/types/objecttype.py b/graphene/types/objecttype.py index d58e5501..2be97358 100644 --- a/graphene/types/objecttype.py +++ b/graphene/types/objecttype.py @@ -49,11 +49,12 @@ class ObjectType(BaseType): if possible_types and cls.is_type_of: raise AssertionError( - ''' + """ {name}.Meta.possible_types will cause type collision with {name}.is_type_of. Please use one or other. - ''' - .format(name=cls.__name__) + """.format( + name=cls.__name__ + ) ) if _meta.fields: diff --git a/graphene/types/resolver.py b/graphene/types/resolver.py index 3b04acb6..d9151b2a 100644 --- a/graphene/types/resolver.py +++ b/graphene/types/resolver.py @@ -12,7 +12,7 @@ default_resolver = attr_resolver def set_default_resolver(resolver): global default_resolver if not callable(resolver): - raise AssertionError('Received non-callable resolver.') + raise AssertionError("Received non-callable resolver.") default_resolver = resolver diff --git a/graphene/types/schema.py b/graphene/types/schema.py index 21c90de5..9250f86d 100644 --- a/graphene/types/schema.py +++ b/graphene/types/schema.py @@ -21,10 +21,7 @@ def assert_valid_root_type(_type): is_graphene_objecttype = inspect.isclass(_type) and issubclass(_type, ObjectType) is_graphql_objecttype = isinstance(_type, GraphQLObjectType) if not (is_graphene_objecttype or is_graphql_objecttype): - raise AssertionError( - "Type {} is not a valid ObjectType." - .format(_type) - ) + raise AssertionError("Type {} is not a valid ObjectType.".format(_type)) class Schema(GraphQLSchema): @@ -57,8 +54,9 @@ class Schema(GraphQLSchema): if not all(isinstance(d, GraphQLDirective) for d in directives): raise AssertionError( - 'Schema directives must be List[GraphQLDirective] if provided but got: {}.' - .format(directives) + "Schema directives must be List[GraphQLDirective] if provided but got: {}.".format( + directives + ) ) self._directives = directives self.build_typemap() @@ -81,10 +79,7 @@ class Schema(GraphQLSchema): """ _type = super(Schema, self).get_type(type_name) if _type is None: - raise AttributeError( - 'Type "{}" not found in the Schema' - .format(type_name) - ) + raise AttributeError('Type "{}" not found in the Schema'.format(type_name)) if isinstance(_type, GrapheneGraphQLType): return _type.graphene_type return _type @@ -98,13 +93,13 @@ class Schema(GraphQLSchema): graphql_type = self.get_type(_type._meta.name) if not graphql_type: raise AssertionError( - "Type {} not found in this schema." - .format(_type._meta.name) + "Type {} not found in this schema.".format(_type._meta.name) ) if graphql_type.graphene_type != _type: raise AssertionError( - 'The type {} does not match with the associated graphene type {}.' - .format(_type, graphql_type.graphene_type) + "The type {} does not match with the associated graphene type {}.".format( + _type, graphql_type.graphene_type + ) ) return graphql_type raise Exception("{} is not a valid GraphQL type.".format(_type)) diff --git a/graphene/types/tests/test_objecttype.py b/graphene/types/tests/test_objecttype.py index d2ae4ade..d7cdd992 100644 --- a/graphene/types/tests/test_objecttype.py +++ b/graphene/types/tests/test_objecttype.py @@ -7,7 +7,6 @@ from ..scalars import String from ..schema import Schema from ..structures import NonNull from ..unmountedtype import UnmountedType -import re class MyType(Interface): @@ -229,14 +228,15 @@ def test_objecttype_with_possible_types_and_is_type_of_should_raise(): def is_type_of(cls, root, context, info): return False - assertion_message = ''' + assertion_message = """ MyObjectType.Meta.possible_types will cause type collision with MyObjectType.is_type_of. Please use one or other. - ''' + """ space_removed_excinfo = str(excinfo.value).replace(" ", "") space_removed_assertion_message = assertion_message.replace(" ", "") assert space_removed_assertion_message == space_removed_excinfo + def test_objecttype_no_fields_output(): class User(ObjectType): name = String() diff --git a/graphene/types/typemap.py b/graphene/types/typemap.py index b0aca624..f34cd50e 100644 --- a/graphene/types/typemap.py +++ b/graphene/types/typemap.py @@ -62,13 +62,13 @@ def resolve_type(resolve_type_func, map, type_name, root, info): graphql_type = map.get(_type._meta.name) if not graphql_type: raise AssertionError( - "Can't find type {} in schema" - .format(_type._meta.name) + "Can't find type {} in schema".format(_type._meta.name) ) if graphql_type.graphene_type != _type: raise AssertionError( - 'The type {} does not match with the associated graphene type {}.' - .format(_type, graphql_type.graphene_type) + "The type {} does not match with the associated graphene type {}.".format( + _type, graphql_type.graphene_type + ) ) return graphql_type @@ -102,8 +102,9 @@ class TypeMap(GraphQLTypeMap): if isinstance(_type, GrapheneGraphQLType): if _type.graphene_type is not type: raise AssertionError( - 'Found different types with the same name in the schema: {}, {}.' - .format(_type.graphene_type, type) + "Found different types with the same name in the schema: {}, {}.".format( + _type.graphene_type, type + ) ) return map @@ -183,8 +184,9 @@ class TypeMap(GraphQLTypeMap): if isinstance(_type, GrapheneGraphQLType): if _type.graphene_type != type: raise AssertionError( - 'Found different types with the same name in the schema: {}, {}.' - .format(_type.graphene_type, type) + "Found different types with the same name in the schema: {}, {}.".format( + _type.graphene_type, type + ) ) return _type @@ -195,8 +197,9 @@ class TypeMap(GraphQLTypeMap): internal_type = map[interface._meta.name] if internal_type.graphene_type != interface: raise AssertionError( - 'Found different types with the same name in the schema: {}, {}.' - .format(internal_type.graphene_type, interface) + "Found different types with the same name in the schema: {}, {}.".format( + internal_type.graphene_type, interface + ) ) interfaces.append(internal_type) return interfaces @@ -223,8 +226,9 @@ class TypeMap(GraphQLTypeMap): if isinstance(_type, GrapheneInterfaceType): if _type.graphene_type != type: raise AssertionError( - 'Found different types with the same name in the schema: {}, {}.' - .format(_type.graphene_type, type) + "Found different types with the same name in the schema: {}, {}.".format( + _type.graphene_type, type + ) ) return _type @@ -266,8 +270,9 @@ class TypeMap(GraphQLTypeMap): internal_type = map[objecttype._meta.name] if internal_type.graphene_type != objecttype: raise AssertionError( - "Found different types with the same name in the schema: {}, {}." - .format(internal_type.graphene_type, objecttype) + "Found different types with the same name in the schema: {}, {}.".format( + internal_type.graphene_type, objecttype + ) ) union_types.append(internal_type) return union_types diff --git a/graphene/types/union.py b/graphene/types/union.py index b4a7b84e..1c14fd71 100644 --- a/graphene/types/union.py +++ b/graphene/types/union.py @@ -25,8 +25,7 @@ class Union(UnmountedType, BaseType): def __init_subclass_with_meta__(cls, types=None, **options): if not (isinstance(types, (list, tuple)) and len(types) > 0): raise AssertionError( - "Must provide types for Union {name}." - .format(name=cls.__name__) + "Must provide types for Union {name}.".format(name=cls.__name__) ) _meta = UnionOptions(cls) _meta.types = types diff --git a/graphene/types/uuid.py b/graphene/types/uuid.py index d7cff7b7..84089a2d 100644 --- a/graphene/types/uuid.py +++ b/graphene/types/uuid.py @@ -15,10 +15,7 @@ class UUID(Scalar): if isinstance(uuid, str): uuid = _UUID(uuid) if not isinstance(uuid, _UUID): - raise AssertionError( - "Expected UUID instance, received {}" - .format(uuid) - ) + raise AssertionError("Expected UUID instance, received {}".format(uuid)) return str(uuid) @staticmethod diff --git a/graphene/utils/annotate.py b/graphene/utils/annotate.py index e63e21d1..18dcd881 100644 --- a/graphene/utils/annotate.py +++ b/graphene/utils/annotate.py @@ -22,10 +22,11 @@ def annotate(_func=None, _trigger_warning=True, **annotations): # We make sure the annotations are valid for key, value in annotations.items(): - if not key in func_signature.parameters: + if func_signature.parameters.get(key, None) is None: raise AssertionError( - 'The key {key} is not a function parameter in the function "{func_name}".' - .format(key=key, func_name=func_name(_func)) + 'The key {key} is not a function parameter in the function "{func_name}".'.format( + key=key, func_name=func_name(_func) + ) ) func_annotations = getattr(_func, "__annotations__", None) diff --git a/graphene/utils/subclass_with_meta.py b/graphene/utils/subclass_with_meta.py index b6dc0553..2889862f 100644 --- a/graphene/utils/subclass_with_meta.py +++ b/graphene/utils/subclass_with_meta.py @@ -44,11 +44,12 @@ class SubclassWithMeta(six.with_metaclass(SubclassWithMeta_Meta)): if abstract: if options: raise AssertionError( - ''' + """ Abstract types can only contain the abstract attribute. Received: abstract, {option_keys} - ''' - .format(option_keys=', '.join(options.keys())) + """.format( + option_keys=", ".join(options.keys()) + ) ) else: super_class = super(cls, cls)