Skip to content

Commit

Permalink
Pass black
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Mar 15, 2020
1 parent a22b09c commit b845862
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 72 deletions.
10 changes: 5 additions & 5 deletions graphene/relay/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init_subclass_with_meta__(cls, node=None, name=None, **options):
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:
Expand Down Expand Up @@ -137,9 +137,9 @@ def type(self):
"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
Expand All @@ -149,7 +149,7 @@ def resolve_connection(cls, connection_type, args, resolved):

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,
Expand Down
16 changes: 7 additions & 9 deletions graphene/relay/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, node, type=False, **kwargs):
# interface
type or node,
id=ID(required=True, description="The ID of the object"),
**kwargs
**kwargs,
)

def get_resolver(self, parent_resolver):
Expand Down Expand Up @@ -93,29 +93,27 @@ def get_node_from_global_id(cls, info, global_id, only_type=None):
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)}"
)
)

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)
Expand Down
20 changes: 6 additions & 14 deletions graphene/relay/tests/test_connection_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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",
)


Expand All @@ -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",
)


Expand Down
12 changes: 3 additions & 9 deletions graphene/types/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def parse_value(value):
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:
Expand Down Expand Up @@ -78,9 +76,7 @@ def parse_value(value):
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):
Expand Down Expand Up @@ -109,9 +105,7 @@ def parse_value(cls, value):
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:
Expand Down
4 changes: 3 additions & 1 deletion graphene/types/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions graphene/types/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ def __init__(
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)
Expand Down
6 changes: 4 additions & 2 deletions graphene/types/mountedtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ def mounted(cls, unmounted): # noqa: N802
"""
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,
)
8 changes: 4 additions & 4 deletions graphene/types/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init_subclass_with_meta__(
output=None,
arguments=None,
_meta=None,
**options
**options,
):
if not _meta:
_meta = MutationOptions(cls)
Expand All @@ -81,9 +81,9 @@ def __init_subclass_with_meta__(
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:
Expand Down
8 changes: 4 additions & 4 deletions graphene/types/objecttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ def __init_subclass_with_meta__(
possible_types=(),
default_resolver=None,
_meta=None,
**options
**options,
):
if not _meta:
_meta = ObjectTypeOptions(cls)

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__):
Expand Down
25 changes: 12 additions & 13 deletions graphene/types/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_):
Expand Down Expand Up @@ -113,9 +113,7 @@ def add_type(self, graphene_type):
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
Expand All @@ -132,9 +130,7 @@ def add_type(self, graphene_type):
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

Expand Down Expand Up @@ -321,7 +317,10 @@ def create_fields_for_type(self, graphene_type, is_input_type=False):
),
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,
Expand Down Expand Up @@ -366,9 +365,9 @@ def resolve_type(self, resolve_type_func, type_name, root, info, _type):
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_
Expand Down
6 changes: 3 additions & 3 deletions graphene/types/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}!"
Expand Down
2 changes: 1 addition & 1 deletion graphene/utils/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import inspect
import warnings

string_types = (type(b""), type(u""))
string_types = (type(b""), type(""))


def warn_deprecation(text):
Expand Down

0 comments on commit b845862

Please sign in to comment.