mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-29 17:29:51 +03:00
changes by linter
This commit is contained in:
parent
f38fc5136f
commit
a212c8a422
|
@ -46,12 +46,11 @@ def get_complete_version(version=None):
|
||||||
from graphene import VERSION as version
|
from graphene import VERSION as version
|
||||||
else:
|
else:
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=len(version) is 5,
|
condition=len(version) is 5, message="Wrong tuple provided"
|
||||||
message="Wrong tuple provided"
|
|
||||||
)
|
)
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=version[3] in ("alpha", "beta", "rc", "final"),
|
condition=version[3] in ("alpha", "beta", "rc", "final"),
|
||||||
message="Version not correct."
|
message="Version not correct.",
|
||||||
)
|
)
|
||||||
|
|
||||||
return version
|
return version
|
||||||
|
|
|
@ -55,7 +55,7 @@ class Connection(ObjectType):
|
||||||
_meta = ConnectionOptions(cls)
|
_meta = ConnectionOptions(cls)
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=node,
|
condition=node,
|
||||||
message="You have to provide a node in {}.Meta".format(cls.__name__)
|
message="You have to provide a node in {}.Meta".format(cls.__name__),
|
||||||
)
|
)
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=issubclass(
|
condition=issubclass(
|
||||||
|
@ -63,7 +63,7 @@ class Connection(ObjectType):
|
||||||
),
|
),
|
||||||
message=('Received incompatible node "{}" for Connection {}.').format(
|
message=('Received incompatible node "{}" for Connection {}.').format(
|
||||||
node, cls.__name__
|
node, cls.__name__
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
base_name = re.sub("Connection$", "", name or cls.__name__) or node._meta.name
|
base_name = re.sub("Connection$", "", name or cls.__name__) or node._meta.name
|
||||||
|
@ -143,7 +143,7 @@ class IterableConnectionField(Field):
|
||||||
condition=issubclass(connection_type, Connection),
|
condition=issubclass(connection_type, Connection),
|
||||||
message='{} type have to be a subclass of Connection. Received "{}".'.format(
|
message='{} type have to be a subclass of Connection. Received "{}".'.format(
|
||||||
self.__class__.__name__, connection_type
|
self.__class__.__name__, connection_type
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
return type
|
return type
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ class IterableConnectionField(Field):
|
||||||
Received "{}"
|
Received "{}"
|
||||||
""".format(
|
""".format(
|
||||||
connection_type, resolved
|
connection_type, resolved
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
connection = connection_from_list(
|
connection = connection_from_list(
|
||||||
|
|
|
@ -17,14 +17,10 @@ class ClientIDMutation(Mutation):
|
||||||
input_class = getattr(cls, "Input", None)
|
input_class = getattr(cls, "Input", None)
|
||||||
base_name = re.sub("Payload$", "", name or cls.__name__)
|
base_name = re.sub("Payload$", "", name or cls.__name__)
|
||||||
|
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(condition=not output, message="Can't specify any output")
|
||||||
condition=not output,
|
|
||||||
message="Can't specify any output"
|
|
||||||
)
|
|
||||||
|
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=not arguments,
|
condition=not arguments, message="Can't specify any arguments"
|
||||||
message="Can't specify any arguments"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
bases = (InputObjectType,)
|
bases = (InputObjectType,)
|
||||||
|
@ -50,10 +46,8 @@ class ClientIDMutation(Mutation):
|
||||||
if cls.mutate and cls.mutate.__func__ == ClientIDMutation.mutate.__func__:
|
if cls.mutate and cls.mutate.__func__ == ClientIDMutation.mutate.__func__:
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=mutate_and_get_payload,
|
condition=mutate_and_get_payload,
|
||||||
message="{name}.mutate_and_get_payload method is required" \
|
message="{name}.mutate_and_get_payload method is required"
|
||||||
" in a ClientIDMutation.".format(
|
" in a ClientIDMutation.".format(name=name or cls.__name__),
|
||||||
name=name or cls.__name__
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not name:
|
if not name:
|
||||||
|
|
|
@ -7,7 +7,6 @@ from graphql_relay import from_global_id, to_global_id
|
||||||
from ..types import ID, Field, Interface, ObjectType
|
from ..types import ID, Field, Interface, ObjectType
|
||||||
from ..types.interface import InterfaceOptions
|
from ..types.interface import InterfaceOptions
|
||||||
from ..types.utils import get_type
|
from ..types.utils import get_type
|
||||||
from ..utils.comparison_helper import raise_assertion_if_not
|
|
||||||
|
|
||||||
|
|
||||||
def is_node(objecttype):
|
def is_node(objecttype):
|
||||||
|
|
|
@ -76,9 +76,7 @@ def to_arguments(args, extra_args=None):
|
||||||
arg_name = default_name or arg.name
|
arg_name = default_name or arg.name
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=arg_name not in arguments,
|
condition=arg_name not in arguments,
|
||||||
message='More than one Argument have same name "{}".'.format(
|
message='More than one Argument have same name "{}".'.format(arg_name),
|
||||||
arg_name
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
arguments[arg_name] = arg
|
arguments[arg_name] = arg
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,7 @@ class BaseType(SubclassWithMeta):
|
||||||
@classmethod
|
@classmethod
|
||||||
def __init_subclass_with_meta__(cls, name=None, description=None, _meta=None):
|
def __init_subclass_with_meta__(cls, name=None, description=None, _meta=None):
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition="_meta" not in cls.__dict__,
|
condition="_meta" not in cls.__dict__, message="Can't assign directly meta"
|
||||||
message="Can't assign directly meta"
|
|
||||||
)
|
)
|
||||||
if not _meta:
|
if not _meta:
|
||||||
return
|
return
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Date(Scalar):
|
||||||
date = date.date()
|
date = date.date()
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=isinstance(date, datetime.date),
|
condition=isinstance(date, datetime.date),
|
||||||
message='Received not compatible date "{}"'.format(repr(date))
|
message='Received not compatible date "{}"'.format(repr(date)),
|
||||||
)
|
)
|
||||||
return date.isoformat()
|
return date.isoformat()
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class DateTime(Scalar):
|
||||||
def serialize(dt):
|
def serialize(dt):
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=isinstance(dt, (datetime.datetime, datetime.date)),
|
condition=isinstance(dt, (datetime.datetime, datetime.date)),
|
||||||
message='Received not compatible datetime "{}"'.format(repr(dt))
|
message='Received not compatible datetime "{}"'.format(repr(dt)),
|
||||||
)
|
)
|
||||||
return dt.isoformat()
|
return dt.isoformat()
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ class Time(Scalar):
|
||||||
def serialize(time):
|
def serialize(time):
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=isinstance(time, datetime.time),
|
condition=isinstance(time, datetime.time),
|
||||||
message='Received not compatible time "{}"'.format(repr(time))
|
message='Received not compatible time "{}"'.format(repr(time)),
|
||||||
)
|
)
|
||||||
return time.isoformat()
|
return time.isoformat()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -39,19 +39,19 @@ class Field(MountedType):
|
||||||
condition=not args or isinstance(args, Mapping),
|
condition=not args or isinstance(args, Mapping),
|
||||||
message='Arguments in a field have to be a mapping, received "{}".'.format(
|
message='Arguments in a field have to be a mapping, received "{}".'.format(
|
||||||
args
|
args
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=not(source and resolver),
|
condition=not (source and resolver),
|
||||||
message="A Field cannot have a source and a resolver in at the same time."
|
message="A Field cannot have a source and a resolver in at the same time.",
|
||||||
)
|
)
|
||||||
|
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=not callable(default_value),
|
condition=not callable(default_value),
|
||||||
message='The default value can not be a function but received "{}".'.format(
|
message='The default value can not be a function but received "{}".'.format(
|
||||||
base_type(default_value)
|
base_type(default_value)
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if required:
|
if required:
|
||||||
|
|
|
@ -11,7 +11,7 @@ class MountedType(OrderedType):
|
||||||
"""
|
"""
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=isinstance(unmounted, UnmountedType),
|
condition=isinstance(unmounted, UnmountedType),
|
||||||
message="{} can't mount {}".format(cls.__name__, repr(unmounted))
|
message="{} can't mount {}".format(cls.__name__, repr(unmounted)),
|
||||||
)
|
)
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
|
|
|
@ -65,8 +65,8 @@ class Mutation(ObjectType):
|
||||||
mutate = getattr(cls, "mutate", None)
|
mutate = getattr(cls, "mutate", None)
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=mutate,
|
condition=mutate,
|
||||||
message="All mutations must define a mutate method in it"
|
message="All mutations must define a mutate method in it",
|
||||||
)
|
)
|
||||||
resolver = get_unbound_function(mutate)
|
resolver = get_unbound_function(mutate)
|
||||||
|
|
||||||
if _meta.fields:
|
if _meta.fields:
|
||||||
|
|
|
@ -44,7 +44,7 @@ class ObjectType(BaseType):
|
||||||
condition=issubclass(interface, Interface),
|
condition=issubclass(interface, Interface),
|
||||||
message='All interfaces of {} must be a subclass of Interface. Received "{}".'.format(
|
message='All interfaces of {} must be a subclass of Interface. Received "{}".'.format(
|
||||||
cls.__name__, interface
|
cls.__name__, interface
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
fields.update(interface._meta.fields)
|
fields.update(interface._meta.fields)
|
||||||
|
|
||||||
|
@ -53,11 +53,10 @@ class ObjectType(BaseType):
|
||||||
|
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=not (possible_types and cls.is_type_of),
|
condition=not (possible_types and cls.is_type_of),
|
||||||
message=("{name}.Meta.possible_types will cause type collision with {name}.is_type_of. " \
|
message=(
|
||||||
"Please use one or other.".format(
|
"{name}.Meta.possible_types will cause type collision with {name}.is_type_of. "
|
||||||
name=cls.__name__
|
"Please use one or other.".format(name=cls.__name__)
|
||||||
)
|
),
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if _meta.fields:
|
if _meta.fields:
|
||||||
|
|
|
@ -23,7 +23,7 @@ def assert_valid_root_type(_type):
|
||||||
is_graphql_objecttype = isinstance(_type, GraphQLObjectType)
|
is_graphql_objecttype = isinstance(_type, GraphQLObjectType)
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=is_graphene_objecttype or is_graphql_objecttype,
|
condition=is_graphene_objecttype or is_graphql_objecttype,
|
||||||
message="Type {} is not a valid ObjectType.".format(_type)
|
message="Type {} is not a valid ObjectType.".format(_type),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class Schema(GraphQLSchema):
|
||||||
condition=all(isinstance(d, GraphQLDirective) for d in directives),
|
condition=all(isinstance(d, GraphQLDirective) for d in directives),
|
||||||
message="Schema directives must be List[GraphQLDirective] if provided but got: {}.".format(
|
message="Schema directives must be List[GraphQLDirective] if provided but got: {}.".format(
|
||||||
directives
|
directives
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
self._directives = directives
|
self._directives = directives
|
||||||
self.build_typemap()
|
self.build_typemap()
|
||||||
|
|
|
@ -72,7 +72,7 @@ class NonNull(Structure):
|
||||||
condition=not isinstance(self._of_type, NonNull),
|
condition=not isinstance(self._of_type, NonNull),
|
||||||
message="Can only create NonNull of a Nullable GraphQLType but got: {}.".format(
|
message="Can only create NonNull of a Nullable GraphQLType but got: {}.".format(
|
||||||
self._of_type
|
self._of_type
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -63,13 +63,13 @@ def resolve_type(resolve_type_func, map, type_name, root, info):
|
||||||
graphql_type = map.get(_type._meta.name)
|
graphql_type = map.get(_type._meta.name)
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=graphql_type,
|
condition=graphql_type,
|
||||||
message="Can't find type {} in schema".format(_type._meta.name)
|
message="Can't find type {} in schema".format(_type._meta.name),
|
||||||
)
|
)
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=graphql_type.graphene_type is _type,
|
condition=graphql_type.graphene_type is _type,
|
||||||
message="The type {} does not match with the associated graphene type {}.".format(
|
message="The type {} does not match with the associated graphene type {}.".format(
|
||||||
_type, graphql_type.graphene_type
|
_type, graphql_type.graphene_type
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
return graphql_type
|
return graphql_type
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
condition=_type.graphene_type is type,
|
condition=_type.graphene_type is type,
|
||||||
message="Found different types with the same name in the schema: {}, {}.".format(
|
message="Found different types with the same name in the schema: {}, {}.".format(
|
||||||
_type.graphene_type, type
|
_type.graphene_type, type
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
return map
|
return map
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
condition=_type.graphene_type is type,
|
condition=_type.graphene_type is type,
|
||||||
message="Found different types with the same name in the schema: {}, {}.".format(
|
message="Found different types with the same name in the schema: {}, {}.".format(
|
||||||
_type.graphene_type, type
|
_type.graphene_type, type
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
return _type
|
return _type
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
condition=_type.graphene_type is type,
|
condition=_type.graphene_type is type,
|
||||||
message="Found different types with the same name in the schema: {}, {}.".format(
|
message="Found different types with the same name in the schema: {}, {}.".format(
|
||||||
_type.graphene_type, type
|
_type.graphene_type, type
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
return _type
|
return _type
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Union(UnmountedType, BaseType):
|
||||||
def __init_subclass_with_meta__(cls, types=None, **options):
|
def __init_subclass_with_meta__(cls, types=None, **options):
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=isinstance(types, (list, tuple)) and len(types) > 0,
|
condition=isinstance(types, (list, tuple)) and len(types) > 0,
|
||||||
message="Must provide types for Union {name}.".format(name=cls.__name__)
|
message="Must provide types for Union {name}.".format(name=cls.__name__),
|
||||||
)
|
)
|
||||||
_meta = UnionOptions(cls)
|
_meta = UnionOptions(cls)
|
||||||
_meta.types = types
|
_meta.types = types
|
||||||
|
|
|
@ -17,7 +17,7 @@ class UUID(Scalar):
|
||||||
uuid = _UUID(uuid)
|
uuid = _UUID(uuid)
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=isinstance(uuid, _UUID),
|
condition=isinstance(uuid, _UUID),
|
||||||
message="Expected UUID instance, received {}".format(uuid)
|
message="Expected UUID instance, received {}".format(uuid),
|
||||||
)
|
)
|
||||||
return str(uuid)
|
return str(uuid)
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,10 @@ def annotate(_func=None, _trigger_warning=True, **annotations):
|
||||||
# We make sure the annotations are valid
|
# We make sure the annotations are valid
|
||||||
for key, value in annotations.items():
|
for key, value in annotations.items():
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition= key in func_signature.parameters,
|
condition=key in func_signature.parameters,
|
||||||
message='The key {key} is not a function parameter in the function "{func_name}".'.format(
|
message='The key {key} is not a function parameter in the function "{func_name}".'.format(
|
||||||
key=key, func_name=func_name(_func)
|
key=key, func_name=func_name(_func)
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
func_annotations = getattr(_func, "__annotations__", None)
|
func_annotations = getattr(_func, "__annotations__", None)
|
||||||
|
|
|
@ -7,7 +7,6 @@ from .props import props
|
||||||
from .comparison_helper import raise_assertion_if_not
|
from .comparison_helper import raise_assertion_if_not
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SubclassWithMeta_Meta(InitSubclassMeta):
|
class SubclassWithMeta_Meta(InitSubclassMeta):
|
||||||
_meta = None
|
_meta = None
|
||||||
|
|
||||||
|
@ -46,10 +45,10 @@ class SubclassWithMeta(six.with_metaclass(SubclassWithMeta_Meta)):
|
||||||
if abstract:
|
if abstract:
|
||||||
raise_assertion_if_not(
|
raise_assertion_if_not(
|
||||||
condition=not options,
|
condition=not options,
|
||||||
message="Abstract types can only contain the abstract attribute. " \
|
message="Abstract types can only contain the abstract attribute. "
|
||||||
"Received: abstract, {option_keys}".format(
|
"Received: abstract, {option_keys}".format(
|
||||||
option_keys=", ".join(options.keys())
|
option_keys=", ".join(options.keys())
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
super_class = super(cls, cls)
|
super_class = super(cls, cls)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user