From b845862a670704856fcdaf181a7885e3a153e727 Mon Sep 17 00:00:00 2001 From: Syrus Date: Sat, 14 Mar 2020 17:25:03 -0700 Subject: [PATCH] Pass black --- graphene/relay/connection.py | 10 ++++---- graphene/relay/node.py | 16 ++++++------ graphene/relay/tests/test_connection_query.py | 20 +++++---------- graphene/types/datetime.py | 12 +++------ graphene/types/decimal.py | 4 ++- graphene/types/field.py | 14 +++++------ graphene/types/mountedtype.py | 6 +++-- graphene/types/mutation.py | 8 +++--- graphene/types/objecttype.py | 8 +++--- graphene/types/schema.py | 25 +++++++++---------- graphene/types/structures.py | 6 ++--- graphene/utils/deprecated.py | 2 +- 12 files changed, 59 insertions(+), 72 deletions(-) diff --git a/graphene/relay/connection.py b/graphene/relay/connection.py index 7fd8356b..90b558a1 100644 --- a/graphene/relay/connection.py +++ b/graphene/relay/connection.py @@ -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, diff --git a/graphene/relay/node.py b/graphene/relay/node.py index e7159cd0..a9d36adc 100644 --- a/graphene/relay/node.py +++ b/graphene/relay/node.py @@ -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) diff --git a/graphene/relay/tests/test_connection_query.py b/graphene/relay/tests/test_connection_query.py index cf75c09d..cac4b65b 100644 --- a/graphene/relay/tests/test_connection_query.py +++ b/graphene/relay/tests/test_connection_query.py @@ -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", ) diff --git a/graphene/types/datetime.py b/graphene/types/datetime.py index 9d95bed9..92234ba6 100644 --- a/graphene/types/datetime.py +++ b/graphene/types/datetime.py @@ -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: diff --git a/graphene/types/decimal.py b/graphene/types/decimal.py index 8895a916..028d6d28 100644 --- a/graphene/types/decimal.py +++ b/graphene/types/decimal.py @@ -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 diff --git a/graphene/types/field.py b/graphene/types/field.py index 9bc36afb..b2c7766a 100644 --- a/graphene/types/field.py +++ b/graphene/types/field.py @@ -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) diff --git a/graphene/types/mountedtype.py b/graphene/types/mountedtype.py index 3e88662d..c42383e2 100644 --- a/graphene/types/mountedtype.py +++ b/graphene/types/mountedtype.py @@ -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, ) diff --git a/graphene/types/mutation.py b/graphene/types/mutation.py index ad7d34c4..6e041bbf 100644 --- a/graphene/types/mutation.py +++ b/graphene/types/mutation.py @@ -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: diff --git a/graphene/types/objecttype.py b/graphene/types/objecttype.py index 7ccf09fa..e8dceb5a 100644 --- a/graphene/types/objecttype.py +++ b/graphene/types/objecttype.py @@ -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__): diff --git a/graphene/types/schema.py b/graphene/types/schema.py index dc1b08cc..458948f4 100644 --- a/graphene/types/schema.py +++ b/graphene/types/schema.py @@ -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_ diff --git a/graphene/types/structures.py b/graphene/types/structures.py index 94b3c8e3..b5a41103 100644 --- a/graphene/types/structures.py +++ b/graphene/types/structures.py @@ -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}!" diff --git a/graphene/utils/deprecated.py b/graphene/utils/deprecated.py index fcbe8e0c..71a5bb40 100644 --- a/graphene/utils/deprecated.py +++ b/graphene/utils/deprecated.py @@ -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):