Pass black

This commit is contained in:
Syrus 2020-03-14 17:25:03 -07:00
parent a22b09c621
commit b845862a67
12 changed files with 59 additions and 72 deletions

View File

@ -66,7 +66,7 @@ class Connection(ObjectType):
assert node, f"You have to provide a node in {cls.__name__}.Meta" assert node, f"You have to provide a node in {cls.__name__}.Meta"
assert isinstance(node, NonNull) or issubclass( assert isinstance(node, NonNull) or issubclass(
node, (Scalar, Enum, ObjectType, Interface, Union, NonNull) 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 base_name = re.sub("Connection$", "", name or cls.__name__) or node._meta.name
if not 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" "Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#node-connections"
) )
assert issubclass(connection_type, Connection), ( assert issubclass(
f"{self.__class__.__name__} type has to be a subclass of Connection. Received \"{connection_type}\"." connection_type, Connection
) ), f'{self.__class__.__name__} type has to be a subclass of Connection. Received "{connection_type}".'
return type return type
@classmethod @classmethod
@ -149,7 +149,7 @@ class IterableConnectionField(Field):
assert isinstance(resolved, Iterable), ( assert isinstance(resolved, Iterable), (
f"Resolved value from the connection field has to be an iterable or instance of {connection_type}. " 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( connection = connection_from_array(
resolved, resolved,

View File

@ -57,7 +57,7 @@ class NodeField(Field):
# interface # interface
type or node, type or node,
id=ID(required=True, description="The ID of the object"), id=ID(required=True, description="The ID of the object"),
**kwargs **kwargs,
) )
def get_resolver(self, parent_resolver): def get_resolver(self, parent_resolver):
@ -93,7 +93,7 @@ class Node(AbstractNode):
except Exception as e: except Exception as e:
raise Exception( 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". ' 'Make sure it is a base64 encoded string in the format: "TypeName:id". '
f"Exception message: {str(e)}" f"Exception message: {str(e)}"
) )
@ -101,21 +101,19 @@ class Node(AbstractNode):
graphene_type = info.schema.get_type(_type) graphene_type = info.schema.get_type(_type)
if graphene_type is None: if graphene_type is None:
raise Exception( raise Exception(f'Relay Node "{_type}" not found in schema')
f"Relay Node \"{_type}\" not found in schema"
)
graphene_type = graphene_type.graphene_type graphene_type = graphene_type.graphene_type
if only_type: if only_type:
assert graphene_type == only_type, ( assert (
f"Must receive a {only_type._meta.name} id." graphene_type == only_type
) ), f"Must receive a {only_type._meta.name} id."
# We make sure the ObjectType implements the "Node" interface # We make sure the ObjectType implements the "Node" interface
if cls not in graphene_type._meta.interfaces: if cls not in graphene_type._meta.interfaces:
raise Exception( 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) get_node = getattr(graphene_type, "get_node", None)

View File

@ -134,9 +134,7 @@ async def test_respects_an_overly_large_last():
@mark.asyncio @mark.asyncio
async def test_respects_first_and_after(): async def test_respects_first_and_after():
await check( await check(f'first: 2, after: "{cursor_for("B")}"', "CD", has_next_page=True)
f'first: 2, after: \"{cursor_for("B")}\"', "CD", has_next_page=True
)
@mark.asyncio @mark.asyncio
@ -146,9 +144,7 @@ async def test_respects_first_and_after_with_long_first():
@mark.asyncio @mark.asyncio
async def test_respects_last_and_before(): async def test_respects_last_and_before():
await check( await check(f'last: 2, before: "{cursor_for("D")}"', "BC", has_previous_page=True)
f'last: 2, before: "{cursor_for("D")}"', "BC", has_previous_page=True
)
@mark.asyncio @mark.asyncio
@ -168,16 +164,14 @@ async def test_respects_first_and_after_and_before_too_few():
@mark.asyncio @mark.asyncio
async def test_respects_first_and_after_and_before_too_many(): async def test_respects_first_and_after_and_before_too_many():
await check( await check(
f'first: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', f'first: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
"BCD",
) )
@mark.asyncio @mark.asyncio
async def test_respects_first_and_after_and_before_exactly_right(): async def test_respects_first_and_after_and_before_exactly_right():
await check( await check(
f'first: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', f'first: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
"BCD",
) )
@ -193,16 +187,14 @@ async def test_respects_last_and_after_and_before_too_few():
@mark.asyncio @mark.asyncio
async def test_respects_last_and_after_and_before_too_many(): async def test_respects_last_and_after_and_before_too_many():
await check( await check(
f'last: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', f'last: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
"BCD",
) )
@mark.asyncio @mark.asyncio
async def test_respects_last_and_after_and_before_exactly_right(): async def test_respects_last_and_after_and_before_exactly_right():
await check( await check(
f'last: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', f'last: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
"BCD",
) )

View File

@ -37,9 +37,7 @@ class Date(Scalar):
if isinstance(value, datetime.date): if isinstance(value, datetime.date):
return value return value
if not isinstance(value, str): if not isinstance(value, str):
raise GraphQLError( raise GraphQLError(f"Date cannot represent non-string value: {repr(value)}")
f"Date cannot represent non-string value: {repr(value)}"
)
try: try:
return parse_date(value) return parse_date(value)
except ValueError: except ValueError:
@ -78,9 +76,7 @@ class DateTime(Scalar):
try: try:
return parse_datetime(value) return parse_datetime(value)
except ValueError: except ValueError:
raise GraphQLError( raise GraphQLError(f"DateTime cannot represent value: {repr(value)}")
f"DateTime cannot represent value: {repr(value)}"
)
class Time(Scalar): class Time(Scalar):
@ -109,9 +105,7 @@ class Time(Scalar):
if isinstance(value, datetime.time): if isinstance(value, datetime.time):
return value return value
if not isinstance(value, str): if not isinstance(value, str):
raise GraphQLError( raise GraphQLError(f"Time cannot represent non-string value: {repr(value)}")
f"Time cannot represent non-string value: {repr(value)}"
)
try: try:
return parse_time(value) return parse_time(value)
except ValueError: except ValueError:

View File

@ -16,7 +16,9 @@ class Decimal(Scalar):
def serialize(dec): def serialize(dec):
if isinstance(dec, str): if isinstance(dec, str):
dec = _Decimal(dec) 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) return str(dec)
@classmethod @classmethod

View File

@ -72,18 +72,18 @@ class Field(MountedType):
required=False, required=False,
_creation_counter=None, _creation_counter=None,
default_value=None, default_value=None,
**extra_args **extra_args,
): ):
super(Field, self).__init__(_creation_counter=_creation_counter) super(Field, self).__init__(_creation_counter=_creation_counter)
assert not args or isinstance(args, Mapping), ( assert not args or isinstance(
f'Arguments in a field have to be a mapping, received "{args}".' args, Mapping
) ), f'Arguments in a field have to be a mapping, received "{args}".'
assert not ( assert not (
source and resolver source and resolver
), "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."
assert not callable(default_value), ( assert not callable(
f'The default value can not be a function but received "{base_type(default_value)}".' default_value
) ), f'The default value can not be a function but received "{base_type(default_value)}".'
if required: if required:
type = NonNull(type) type = NonNull(type)

View File

@ -8,11 +8,13 @@ class MountedType(OrderedType):
""" """
Mount the UnmountedType instance 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( return cls(
unmounted.get_type(), unmounted.get_type(),
*unmounted.args, *unmounted.args,
_creation_counter=unmounted.creation_counter, _creation_counter=unmounted.creation_counter,
**unmounted.kwargs **unmounted.kwargs,
) )

View File

@ -72,7 +72,7 @@ class Mutation(ObjectType):
output=None, output=None,
arguments=None, arguments=None,
_meta=None, _meta=None,
**options **options,
): ):
if not _meta: if not _meta:
_meta = MutationOptions(cls) _meta = MutationOptions(cls)
@ -81,9 +81,9 @@ class Mutation(ObjectType):
fields = {} fields = {}
for interface in interfaces: for interface in interfaces:
assert issubclass(interface, Interface), ( assert issubclass(
f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".' interface, Interface
) ), f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
fields.update(interface._meta.fields) fields.update(interface._meta.fields)
if not output: if not output:

View File

@ -93,7 +93,7 @@ class ObjectType(BaseType):
possible_types=(), possible_types=(),
default_resolver=None, default_resolver=None,
_meta=None, _meta=None,
**options **options,
): ):
if not _meta: if not _meta:
_meta = ObjectTypeOptions(cls) _meta = ObjectTypeOptions(cls)
@ -101,9 +101,9 @@ class ObjectType(BaseType):
fields = {} fields = {}
for interface in interfaces: for interface in interfaces:
assert issubclass(interface, Interface), ( assert issubclass(
f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".' interface, Interface
) ), f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
fields.update(interface._meta.fields) fields.update(interface._meta.fields)
for base in reversed(cls.__mro__): for base in reversed(cls.__mro__):

View File

@ -58,9 +58,9 @@ def assert_valid_root_type(type_):
return return
is_graphene_objecttype = inspect.isclass(type_) and issubclass(type_, ObjectType) is_graphene_objecttype = inspect.isclass(type_) and issubclass(type_, ObjectType)
is_graphql_objecttype = isinstance(type_, GraphQLObjectType) is_graphql_objecttype = isinstance(type_, GraphQLObjectType)
assert is_graphene_objecttype or is_graphql_objecttype, ( assert (
f"Type {type_} is not a valid ObjectType." is_graphene_objecttype or is_graphql_objecttype
) ), f"Type {type_} is not a valid ObjectType."
def is_graphene_type(type_): def is_graphene_type(type_):
@ -113,9 +113,7 @@ class TypeMap(dict):
try: try:
name = graphene_type._meta.name name = graphene_type._meta.name
except AttributeError: except AttributeError:
raise TypeError( raise TypeError(f"Expected Graphene type, but received: {graphene_type}.")
f"Expected Graphene type, but received: {graphene_type}."
)
graphql_type = self.get(name) graphql_type = self.get(name)
if graphql_type: if graphql_type:
return graphql_type return graphql_type
@ -132,9 +130,7 @@ class TypeMap(dict):
elif issubclass(graphene_type, Union): elif issubclass(graphene_type, Union):
graphql_type = self.construct_union(graphene_type) graphql_type = self.construct_union(graphene_type)
else: else:
raise TypeError( raise TypeError(f"Expected Graphene type, but received: {graphene_type}.")
f"Expected Graphene type, but received: {graphene_type}."
)
self[name] = graphql_type self[name] = graphql_type
return graphql_type return graphql_type
@ -321,7 +317,10 @@ class TypeMap(dict):
), ),
subscribe=field.get_resolver( subscribe=field.get_resolver(
self.get_resolver_for_type( 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, deprecation_reason=field.deprecation_reason,
@ -366,9 +365,9 @@ class TypeMap(dict):
if inspect.isclass(type_) and issubclass(type_, ObjectType): if inspect.isclass(type_) and issubclass(type_, ObjectType):
graphql_type = self.get(type_._meta.name) graphql_type = self.get(type_._meta.name)
assert graphql_type, f"Can't find type {type_._meta.name} in schema" assert graphql_type, f"Can't find type {type_._meta.name} in schema"
assert graphql_type.graphene_type == type_, ( assert (
f"The type {type_} does not match with the associated graphene type {graphql_type.graphene_type}." 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 graphql_type
return type_ return type_

View File

@ -83,9 +83,9 @@ class NonNull(Structure):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(NonNull, self).__init__(*args, **kwargs) super(NonNull, self).__init__(*args, **kwargs)
assert not isinstance(self._of_type, NonNull), ( assert not isinstance(
f"Can only create NonNull of a Nullable GraphQLType but got: {self._of_type}." self._of_type, NonNull
) ), f"Can only create NonNull of a Nullable GraphQLType but got: {self._of_type}."
def __str__(self): def __str__(self):
return f"{self.of_type}!" return f"{self.of_type}!"

View File

@ -2,7 +2,7 @@ import functools
import inspect import inspect
import warnings import warnings
string_types = (type(b""), type(u"")) string_types = (type(b""), type(""))
def warn_deprecation(text): def warn_deprecation(text):