mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-18 03:52:24 +03:00
Pass black
This commit is contained in:
parent
a22b09c621
commit
b845862a67
|
@ -66,7 +66,7 @@ class Connection(ObjectType):
|
|||
assert node, f"You have to provide a node in {cls.__name__}.Meta"
|
||||
assert isinstance(node, NonNull) or issubclass(
|
||||
node, (Scalar, Enum, ObjectType, Interface, Union, NonNull)
|
||||
), (f"Received incompatible node \"{node}\" for Connection {cls.__name__}.")
|
||||
), f'Received incompatible node "{node}" for Connection {cls.__name__}.'
|
||||
|
||||
base_name = re.sub("Connection$", "", name or cls.__name__) or node._meta.name
|
||||
if not name:
|
||||
|
@ -137,9 +137,9 @@ class IterableConnectionField(Field):
|
|||
"Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#node-connections"
|
||||
)
|
||||
|
||||
assert issubclass(connection_type, Connection), (
|
||||
f"{self.__class__.__name__} type has to be a subclass of Connection. Received \"{connection_type}\"."
|
||||
)
|
||||
assert issubclass(
|
||||
connection_type, Connection
|
||||
), f'{self.__class__.__name__} type has to be a subclass of Connection. Received "{connection_type}".'
|
||||
return type
|
||||
|
||||
@classmethod
|
||||
|
@ -149,7 +149,7 @@ class IterableConnectionField(Field):
|
|||
|
||||
assert isinstance(resolved, Iterable), (
|
||||
f"Resolved value from the connection field has to be an iterable or instance of {connection_type}. "
|
||||
f"Received \"{resolved}\""
|
||||
f'Received "{resolved}"'
|
||||
)
|
||||
connection = connection_from_array(
|
||||
resolved,
|
||||
|
|
|
@ -57,7 +57,7 @@ class NodeField(Field):
|
|||
# interface
|
||||
type or node,
|
||||
id=ID(required=True, description="The ID of the object"),
|
||||
**kwargs
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def get_resolver(self, parent_resolver):
|
||||
|
@ -93,7 +93,7 @@ class Node(AbstractNode):
|
|||
except Exception as e:
|
||||
raise Exception(
|
||||
(
|
||||
f"Unable to parse global ID \"{global_id}\". "
|
||||
f'Unable to parse global ID "{global_id}". '
|
||||
'Make sure it is a base64 encoded string in the format: "TypeName:id". '
|
||||
f"Exception message: {str(e)}"
|
||||
)
|
||||
|
@ -101,21 +101,19 @@ class Node(AbstractNode):
|
|||
|
||||
graphene_type = info.schema.get_type(_type)
|
||||
if graphene_type is None:
|
||||
raise Exception(
|
||||
f"Relay Node \"{_type}\" not found in schema"
|
||||
)
|
||||
raise Exception(f'Relay Node "{_type}" not found in schema')
|
||||
|
||||
graphene_type = graphene_type.graphene_type
|
||||
|
||||
if only_type:
|
||||
assert graphene_type == only_type, (
|
||||
f"Must receive a {only_type._meta.name} id."
|
||||
)
|
||||
assert (
|
||||
graphene_type == only_type
|
||||
), f"Must receive a {only_type._meta.name} id."
|
||||
|
||||
# We make sure the ObjectType implements the "Node" interface
|
||||
if cls not in graphene_type._meta.interfaces:
|
||||
raise Exception(
|
||||
f"ObjectType \"{_type}\" does not implement the \"{cls}\" interface."
|
||||
f'ObjectType "{_type}" does not implement the "{cls}" interface.'
|
||||
)
|
||||
|
||||
get_node = getattr(graphene_type, "get_node", None)
|
||||
|
|
|
@ -134,9 +134,7 @@ async def test_respects_an_overly_large_last():
|
|||
|
||||
@mark.asyncio
|
||||
async def test_respects_first_and_after():
|
||||
await check(
|
||||
f'first: 2, after: \"{cursor_for("B")}\"', "CD", has_next_page=True
|
||||
)
|
||||
await check(f'first: 2, after: "{cursor_for("B")}"', "CD", has_next_page=True)
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
|
@ -146,9 +144,7 @@ async def test_respects_first_and_after_with_long_first():
|
|||
|
||||
@mark.asyncio
|
||||
async def test_respects_last_and_before():
|
||||
await check(
|
||||
f'last: 2, before: "{cursor_for("D")}"', "BC", has_previous_page=True
|
||||
)
|
||||
await check(f'last: 2, before: "{cursor_for("D")}"', "BC", has_previous_page=True)
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
|
@ -168,16 +164,14 @@ async def test_respects_first_and_after_and_before_too_few():
|
|||
@mark.asyncio
|
||||
async def test_respects_first_and_after_and_before_too_many():
|
||||
await check(
|
||||
f'first: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"',
|
||||
"BCD",
|
||||
f'first: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
|
||||
)
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_respects_first_and_after_and_before_exactly_right():
|
||||
await check(
|
||||
f'first: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"',
|
||||
"BCD",
|
||||
f'first: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
|
||||
)
|
||||
|
||||
|
||||
|
@ -193,16 +187,14 @@ async def test_respects_last_and_after_and_before_too_few():
|
|||
@mark.asyncio
|
||||
async def test_respects_last_and_after_and_before_too_many():
|
||||
await check(
|
||||
f'last: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"',
|
||||
"BCD",
|
||||
f'last: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
|
||||
)
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_respects_last_and_after_and_before_exactly_right():
|
||||
await check(
|
||||
f'last: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"',
|
||||
"BCD",
|
||||
f'last: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -37,9 +37,7 @@ class Date(Scalar):
|
|||
if isinstance(value, datetime.date):
|
||||
return value
|
||||
if not isinstance(value, str):
|
||||
raise GraphQLError(
|
||||
f"Date cannot represent non-string value: {repr(value)}"
|
||||
)
|
||||
raise GraphQLError(f"Date cannot represent non-string value: {repr(value)}")
|
||||
try:
|
||||
return parse_date(value)
|
||||
except ValueError:
|
||||
|
@ -78,9 +76,7 @@ class DateTime(Scalar):
|
|||
try:
|
||||
return parse_datetime(value)
|
||||
except ValueError:
|
||||
raise GraphQLError(
|
||||
f"DateTime cannot represent value: {repr(value)}"
|
||||
)
|
||||
raise GraphQLError(f"DateTime cannot represent value: {repr(value)}")
|
||||
|
||||
|
||||
class Time(Scalar):
|
||||
|
@ -109,9 +105,7 @@ class Time(Scalar):
|
|||
if isinstance(value, datetime.time):
|
||||
return value
|
||||
if not isinstance(value, str):
|
||||
raise GraphQLError(
|
||||
f"Time cannot represent non-string value: {repr(value)}"
|
||||
)
|
||||
raise GraphQLError(f"Time cannot represent non-string value: {repr(value)}")
|
||||
try:
|
||||
return parse_time(value)
|
||||
except ValueError:
|
||||
|
|
|
@ -16,7 +16,9 @@ class Decimal(Scalar):
|
|||
def serialize(dec):
|
||||
if isinstance(dec, str):
|
||||
dec = _Decimal(dec)
|
||||
assert isinstance(dec, _Decimal), f'Received not compatible Decimal "{repr(dec)}"'
|
||||
assert isinstance(
|
||||
dec, _Decimal
|
||||
), f'Received not compatible Decimal "{repr(dec)}"'
|
||||
return str(dec)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -72,18 +72,18 @@ class Field(MountedType):
|
|||
required=False,
|
||||
_creation_counter=None,
|
||||
default_value=None,
|
||||
**extra_args
|
||||
**extra_args,
|
||||
):
|
||||
super(Field, self).__init__(_creation_counter=_creation_counter)
|
||||
assert not args or isinstance(args, Mapping), (
|
||||
f'Arguments in a field have to be a mapping, received "{args}".'
|
||||
)
|
||||
assert not args or isinstance(
|
||||
args, Mapping
|
||||
), f'Arguments in a field have to be a mapping, received "{args}".'
|
||||
assert not (
|
||||
source and resolver
|
||||
), "A Field cannot have a source and a resolver in at the same time."
|
||||
assert not callable(default_value), (
|
||||
f'The default value can not be a function but received "{base_type(default_value)}".'
|
||||
)
|
||||
assert not callable(
|
||||
default_value
|
||||
), f'The default value can not be a function but received "{base_type(default_value)}".'
|
||||
|
||||
if required:
|
||||
type = NonNull(type)
|
||||
|
|
|
@ -8,11 +8,13 @@ class MountedType(OrderedType):
|
|||
"""
|
||||
Mount the UnmountedType instance
|
||||
"""
|
||||
assert isinstance(unmounted, UnmountedType), f"{cls.__name__} can't mount {repr(unmounted)}"
|
||||
assert isinstance(
|
||||
unmounted, UnmountedType
|
||||
), f"{cls.__name__} can't mount {repr(unmounted)}"
|
||||
|
||||
return cls(
|
||||
unmounted.get_type(),
|
||||
*unmounted.args,
|
||||
_creation_counter=unmounted.creation_counter,
|
||||
**unmounted.kwargs
|
||||
**unmounted.kwargs,
|
||||
)
|
||||
|
|
|
@ -72,7 +72,7 @@ class Mutation(ObjectType):
|
|||
output=None,
|
||||
arguments=None,
|
||||
_meta=None,
|
||||
**options
|
||||
**options,
|
||||
):
|
||||
if not _meta:
|
||||
_meta = MutationOptions(cls)
|
||||
|
@ -81,9 +81,9 @@ class Mutation(ObjectType):
|
|||
fields = {}
|
||||
|
||||
for interface in interfaces:
|
||||
assert issubclass(interface, Interface), (
|
||||
f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
|
||||
)
|
||||
assert issubclass(
|
||||
interface, Interface
|
||||
), f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
|
||||
fields.update(interface._meta.fields)
|
||||
|
||||
if not output:
|
||||
|
|
|
@ -93,7 +93,7 @@ class ObjectType(BaseType):
|
|||
possible_types=(),
|
||||
default_resolver=None,
|
||||
_meta=None,
|
||||
**options
|
||||
**options,
|
||||
):
|
||||
if not _meta:
|
||||
_meta = ObjectTypeOptions(cls)
|
||||
|
@ -101,9 +101,9 @@ class ObjectType(BaseType):
|
|||
fields = {}
|
||||
|
||||
for interface in interfaces:
|
||||
assert issubclass(interface, Interface), (
|
||||
f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
|
||||
)
|
||||
assert issubclass(
|
||||
interface, Interface
|
||||
), f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
|
||||
fields.update(interface._meta.fields)
|
||||
|
||||
for base in reversed(cls.__mro__):
|
||||
|
|
|
@ -58,9 +58,9 @@ def assert_valid_root_type(type_):
|
|||
return
|
||||
is_graphene_objecttype = inspect.isclass(type_) and issubclass(type_, ObjectType)
|
||||
is_graphql_objecttype = isinstance(type_, GraphQLObjectType)
|
||||
assert is_graphene_objecttype or is_graphql_objecttype, (
|
||||
f"Type {type_} is not a valid ObjectType."
|
||||
)
|
||||
assert (
|
||||
is_graphene_objecttype or is_graphql_objecttype
|
||||
), f"Type {type_} is not a valid ObjectType."
|
||||
|
||||
|
||||
def is_graphene_type(type_):
|
||||
|
@ -113,9 +113,7 @@ class TypeMap(dict):
|
|||
try:
|
||||
name = graphene_type._meta.name
|
||||
except AttributeError:
|
||||
raise TypeError(
|
||||
f"Expected Graphene type, but received: {graphene_type}."
|
||||
)
|
||||
raise TypeError(f"Expected Graphene type, but received: {graphene_type}.")
|
||||
graphql_type = self.get(name)
|
||||
if graphql_type:
|
||||
return graphql_type
|
||||
|
@ -132,9 +130,7 @@ class TypeMap(dict):
|
|||
elif issubclass(graphene_type, Union):
|
||||
graphql_type = self.construct_union(graphene_type)
|
||||
else:
|
||||
raise TypeError(
|
||||
f"Expected Graphene type, but received: {graphene_type}."
|
||||
)
|
||||
raise TypeError(f"Expected Graphene type, but received: {graphene_type}.")
|
||||
self[name] = graphql_type
|
||||
return graphql_type
|
||||
|
||||
|
@ -321,7 +317,10 @@ class TypeMap(dict):
|
|||
),
|
||||
subscribe=field.get_resolver(
|
||||
self.get_resolver_for_type(
|
||||
graphene_type, f"subscribe_{name}", name, field.default_value
|
||||
graphene_type,
|
||||
f"subscribe_{name}",
|
||||
name,
|
||||
field.default_value,
|
||||
)
|
||||
),
|
||||
deprecation_reason=field.deprecation_reason,
|
||||
|
@ -366,9 +365,9 @@ class TypeMap(dict):
|
|||
if inspect.isclass(type_) and issubclass(type_, ObjectType):
|
||||
graphql_type = self.get(type_._meta.name)
|
||||
assert graphql_type, f"Can't find type {type_._meta.name} in schema"
|
||||
assert graphql_type.graphene_type == type_, (
|
||||
f"The type {type_} does not match with the associated graphene type {graphql_type.graphene_type}."
|
||||
)
|
||||
assert (
|
||||
graphql_type.graphene_type == type_
|
||||
), f"The type {type_} does not match with the associated graphene type {graphql_type.graphene_type}."
|
||||
return graphql_type
|
||||
|
||||
return type_
|
||||
|
|
|
@ -83,9 +83,9 @@ class NonNull(Structure):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(NonNull, self).__init__(*args, **kwargs)
|
||||
assert not isinstance(self._of_type, NonNull), (
|
||||
f"Can only create NonNull of a Nullable GraphQLType but got: {self._of_type}."
|
||||
)
|
||||
assert not isinstance(
|
||||
self._of_type, NonNull
|
||||
), f"Can only create NonNull of a Nullable GraphQLType but got: {self._of_type}."
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.of_type}!"
|
||||
|
|
|
@ -2,7 +2,7 @@ import functools
|
|||
import inspect
|
||||
import warnings
|
||||
|
||||
string_types = (type(b""), type(u""))
|
||||
string_types = (type(b""), type(""))
|
||||
|
||||
|
||||
def warn_deprecation(text):
|
||||
|
|
Loading…
Reference in New Issue
Block a user