Skip to content

Commit

Permalink
Reformat with newer black version
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Sep 2, 2024
1 parent c6360e8 commit b559a79
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 113 deletions.
14 changes: 8 additions & 6 deletions src/graphql/language/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,11 @@ def parse_variable_definition(self) -> VariableDefinitionNode:
return VariableDefinitionNode(
variable=self.parse_variable(),
type=self.expect_token(TokenKind.COLON) and self.parse_type_reference(),
default_value=self.parse_const_value_literal()
if self.expect_optional_token(TokenKind.EQUALS)
else None,
default_value=(
self.parse_const_value_literal()
if self.expect_optional_token(TokenKind.EQUALS)
else None
),
directives=self.parse_const_directives(),
loc=self.loc(start),
)
Expand Down Expand Up @@ -390,9 +392,9 @@ def parse_field(self) -> FieldNode:
name=name,
arguments=self.parse_arguments(False),
directives=self.parse_directives(False),
selection_set=self.parse_selection_set()
if self.peek(TokenKind.BRACE_L)
else None,
selection_set=(
self.parse_selection_set() if self.peek(TokenKind.BRACE_L) else None
),
loc=self.loc(start),
)

Expand Down
8 changes: 5 additions & 3 deletions src/graphql/language/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ def is_const_value_node(node: Node) -> bool:
return is_value_node(node) and (
any(is_const_value_node(value) for value in node.values)
if isinstance(node, ListValueNode)
else any(is_const_value_node(field.value) for field in node.fields)
if isinstance(node, ObjectValueNode)
else not isinstance(node, VariableNode)
else (
any(is_const_value_node(field.value) for field in node.fields)
if isinstance(node, ObjectValueNode)
else not isinstance(node, VariableNode)
)
)


Expand Down
8 changes: 5 additions & 3 deletions src/graphql/language/print_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ def print_source_location(source: Source, source_location: SourceLocation) -> st
("|", "^".rjust(sub_line_column_num)),
(
"|",
sub_lines[sub_line_index + 1]
if sub_line_index < len(sub_lines) - 1
else None,
(
sub_lines[sub_line_index + 1]
if sub_line_index < len(sub_lines) - 1
else None
),
),
)

Expand Down
12 changes: 7 additions & 5 deletions src/graphql/pyutils/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ def inspect_recursive(value: Any, seen_values: List) -> str:
items = trunc_list(items)
if isinstance(value, dict):
s = ", ".join(
"..."
if v is ELLIPSIS
else inspect_recursive(v[0], seen_values)
+ ": "
+ inspect_recursive(v[1], seen_values)
(
"..."
if v is ELLIPSIS
else inspect_recursive(v[0], seen_values)
+ ": "
+ inspect_recursive(v[1], seen_values)
)
for v in items
)
else:
Expand Down
85 changes: 47 additions & 38 deletions src/graphql/type/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,22 @@ def to_kwargs(self) -> GraphQLScalarTypeKwargs:
# noinspection PyArgumentList
return GraphQLScalarTypeKwargs( # type: ignore
super().to_kwargs(),
serialize=None
if self.serialize is GraphQLScalarType.serialize
else self.serialize,
parse_value=None
if self.parse_value is GraphQLScalarType.parse_value
else self.parse_value,
parse_literal=None
if getattr(self.parse_literal, "__func__", None)
is GraphQLScalarType.parse_literal
else self.parse_literal,
serialize=(
None
if self.serialize is GraphQLScalarType.serialize
else self.serialize
),
parse_value=(
None
if self.parse_value is GraphQLScalarType.parse_value
else self.parse_value
),
parse_literal=(
None
if getattr(self.parse_literal, "__func__", None)
is GraphQLScalarType.parse_literal
else self.parse_literal
),
specified_by_url=self.specified_by_url,
)

Expand Down Expand Up @@ -517,9 +523,11 @@ def __init__(
)
else:
args = {
assert_name(name): value
if isinstance(value, GraphQLArgument)
else GraphQLArgument(cast(GraphQLInputType, value))
assert_name(name): (
value
if isinstance(value, GraphQLArgument)
else GraphQLArgument(cast(GraphQLInputType, value))
)
for name, value in args.items()
}
if resolve is not None and not callable(resolve):
Expand Down Expand Up @@ -824,9 +832,9 @@ def fields(self) -> GraphQLFieldMap:
f"{self.name} fields must be GraphQLField or output type objects."
)
return {
assert_name(name): value
if isinstance(value, GraphQLField)
else GraphQLField(value) # type: ignore
assert_name(name): (
value if isinstance(value, GraphQLField) else GraphQLField(value)
) # type: ignore
for name, value in fields.items()
}

Expand Down Expand Up @@ -958,9 +966,9 @@ def fields(self) -> GraphQLFieldMap:
f"{self.name} fields must be GraphQLField or output type objects."
)
return {
assert_name(name): value
if isinstance(value, GraphQLField)
else GraphQLField(value) # type: ignore
assert_name(name): (
value if isinstance(value, GraphQLField) else GraphQLField(value)
) # type: ignore
for name, value in fields.items()
}

Expand Down Expand Up @@ -1181,9 +1189,11 @@ def __init__(
elif names_as_values is True:
values = {key: key for key in values}
values = {
assert_enum_value_name(key): value
if isinstance(value, GraphQLEnumValue)
else GraphQLEnumValue(value)
assert_enum_value_name(key): (
value
if isinstance(value, GraphQLEnumValue)
else GraphQLEnumValue(value)
)
for key, value in values.items()
}
if ast_node and not isinstance(ast_node, EnumTypeDefinitionNode):
Expand Down Expand Up @@ -1441,9 +1451,11 @@ def to_kwargs(self) -> GraphQLInputObjectTypeKwargs:
return GraphQLInputObjectTypeKwargs( # type: ignore
super().to_kwargs(),
fields=self.fields.copy(),
out_type=None
if self.out_type is GraphQLInputObjectType.out_type
else self.out_type,
out_type=(
None
if self.out_type is GraphQLInputObjectType.out_type
else self.out_type
),
)

def __copy__(self) -> "GraphQLInputObjectType": # pragma: no cover
Expand Down Expand Up @@ -1473,9 +1485,11 @@ def fields(self) -> GraphQLInputFieldMap:
" GraphQLInputField or input type objects."
)
return {
assert_name(name): value
if isinstance(value, GraphQLInputField)
else GraphQLInputField(value) # type: ignore
assert_name(name): (
value
if isinstance(value, GraphQLInputField)
else GraphQLInputField(value)
) # type: ignore
for name, value in fields.items()
}

Expand Down Expand Up @@ -1695,18 +1709,15 @@ def assert_nullable_type(type_: Any) -> GraphQLNullableType:


@overload
def get_nullable_type(type_: None) -> None:
...
def get_nullable_type(type_: None) -> None: ...


@overload
def get_nullable_type(type_: GraphQLNullableType) -> GraphQLNullableType:
...
def get_nullable_type(type_: GraphQLNullableType) -> GraphQLNullableType: ...


@overload
def get_nullable_type(type_: GraphQLNonNull) -> GraphQLNullableType:
...
def get_nullable_type(type_: GraphQLNonNull) -> GraphQLNullableType: ...


def get_nullable_type(
Expand Down Expand Up @@ -1798,13 +1809,11 @@ def assert_named_type(type_: Any) -> GraphQLNamedType:


@overload
def get_named_type(type_: None) -> None:
...
def get_named_type(type_: None) -> None: ...


@overload
def get_named_type(type_: GraphQLType) -> GraphQLNamedType:
...
def get_named_type(type_: GraphQLType) -> GraphQLNamedType: ...


def get_named_type(type_: Optional[GraphQLType]) -> Optional[GraphQLNamedType]:
Expand Down
16 changes: 10 additions & 6 deletions src/graphql/type/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ def __init__(
assert_name(name)
try:
locations = tuple(
value
if isinstance(value, DirectiveLocation)
else DirectiveLocation[cast(str, value)]
(
value
if isinstance(value, DirectiveLocation)
else DirectiveLocation[cast(str, value)]
)
for value in locations
)
except (KeyError, TypeError):
Expand All @@ -90,9 +92,11 @@ def __init__(
)
else:
args = {
assert_name(name): value
if isinstance(value, GraphQLArgument)
else GraphQLArgument(cast(GraphQLInputType, value))
assert_name(name): (
value
if isinstance(value, GraphQLArgument)
else GraphQLArgument(cast(GraphQLInputType, value))
)
for name, value in args.items()
}
if not isinstance(is_repeatable, bool):
Expand Down
12 changes: 6 additions & 6 deletions src/graphql/type/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ def __init__(
if iface.name in implementations_map:
implementations = implementations_map[iface.name]
else:
implementations = implementations_map[
iface.name
] = InterfaceImplementations(objects=[], interfaces=[])
implementations = implementations_map[iface.name] = (
InterfaceImplementations(objects=[], interfaces=[])
)

implementations.interfaces.append(named_type)
elif is_object_type(named_type):
Expand All @@ -284,9 +284,9 @@ def __init__(
if iface.name in implementations_map:
implementations = implementations_map[iface.name]
else:
implementations = implementations_map[
iface.name
] = InterfaceImplementations(objects=[], interfaces=[])
implementations = implementations_map[iface.name] = (
InterfaceImplementations(objects=[], interfaces=[])
)

implementations.objects.append(named_type)

Expand Down
12 changes: 7 additions & 5 deletions src/graphql/type/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,13 @@ def validate_type_implements_ancestors(
for transitive in iface_interfaces:
if transitive not in type_interfaces:
self.report_error(
f"Type {type_.name} cannot implement {iface.name}"
" because it would create a circular reference."
if transitive is type_
else f"Type {type_.name} must implement {transitive.name}"
f" because it is implemented by {iface.name}.",
(
f"Type {type_.name} cannot implement {iface.name}"
" because it would create a circular reference."
if transitive is type_
else f"Type {type_.name} must implement {transitive.name}"
f" because it is implemented by {iface.name}."
),
get_all_implements_interface_nodes(iface, transitive)
+ get_all_implements_interface_nodes(type_, iface),
)
Expand Down
9 changes: 3 additions & 6 deletions src/graphql/utilities/ast_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,23 @@
@overload
def ast_to_dict(
node: Node, locations: bool = False, cache: Optional[Dict[Node, Any]] = None
) -> Dict:
...
) -> Dict: ...


@overload
def ast_to_dict(
node: Collection[Node],
locations: bool = False,
cache: Optional[Dict[Node, Any]] = None,
) -> List[Node]:
...
) -> List[Node]: ...


@overload
def ast_to_dict(
node: OperationType,
locations: bool = False,
cache: Optional[Dict[Node, Any]] = None,
) -> str:
...
) -> str: ...


def ast_to_dict(
Expand Down
8 changes: 5 additions & 3 deletions src/graphql/utilities/extend_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,11 @@ def build_type(ast_node: TypeDefinitionNode) -> GraphQLNamedType:
replace_directive(directive) for directive in schema_kwargs["directives"]
)
+ tuple(build_directive(directive) for directive in directive_defs),
description=schema_def.description.value
if schema_def and schema_def.description
else None,
description=(
schema_def.description.value
if schema_def and schema_def.description
else None
),
extensions={},
ast_node=schema_def or schema_kwargs["ast_node"],
extension_ast_nodes=schema_kwargs["extension_ast_nodes"]
Expand Down
12 changes: 7 additions & 5 deletions src/graphql/utilities/find_breaking_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def find_directive_changes(
)
)

for (old_directive, new_directive) in directives_diff.persisted:
for old_directive, new_directive in directives_diff.persisted:
args_diff = dict_diff(old_directive.args, new_directive.args)

for arg_name, new_arg in args_diff.added.items():
Expand Down Expand Up @@ -185,10 +185,12 @@ def find_type_changes(
schema_changes.append(
BreakingChange(
BreakingChangeType.TYPE_REMOVED,
f"Standard scalar {type_name} was removed"
" because it is not referenced anymore."
if is_specified_scalar_type(old_type)
else f"{type_name} was removed.",
(
f"Standard scalar {type_name} was removed"
" because it is not referenced anymore."
if is_specified_scalar_type(old_type)
else f"{type_name} was removed."
),
)
)

Expand Down
Loading

0 comments on commit b559a79

Please sign in to comment.