From b559a7914d9ad16714d15207d07ab2b556fd452e Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Mon, 2 Sep 2024 22:22:00 +0200 Subject: [PATCH] Reformat with newer black version --- src/graphql/language/parser.py | 14 +-- src/graphql/language/predicates.py | 8 +- src/graphql/language/print_location.py | 8 +- src/graphql/pyutils/inspect.py | 12 +-- src/graphql/type/definition.py | 85 ++++++++++--------- src/graphql/type/directives.py | 16 ++-- src/graphql/type/schema.py | 12 +-- src/graphql/type/validate.py | 12 +-- src/graphql/utilities/ast_to_dict.py | 9 +- src/graphql/utilities/extend_schema.py | 8 +- .../utilities/find_breaking_changes.py | 12 +-- src/graphql/utilities/type_from_ast.py | 14 ++- .../validation/rules/known_type_names.py | 8 +- .../rules/no_undefined_variables.py | 10 ++- .../validation/rules/no_unused_variables.py | 10 ++- tests/execution/test_subscribe.py | 2 +- tests/execution/test_variables.py | 6 +- tests/fixtures/__init__.py | 1 + tests/type/test_enum.py | 11 ++- 19 files changed, 145 insertions(+), 113 deletions(-) diff --git a/src/graphql/language/parser.py b/src/graphql/language/parser.py index 97af0746..5106647c 100644 --- a/src/graphql/language/parser.py +++ b/src/graphql/language/parser.py @@ -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), ) @@ -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), ) diff --git a/src/graphql/language/predicates.py b/src/graphql/language/predicates.py index 24d7c7a5..75acad38 100644 --- a/src/graphql/language/predicates.py +++ b/src/graphql/language/predicates.py @@ -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) + ) ) diff --git a/src/graphql/language/print_location.py b/src/graphql/language/print_location.py index 6d13b1e1..bf48f30d 100644 --- a/src/graphql/language/print_location.py +++ b/src/graphql/language/print_location.py @@ -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 + ), ), ) diff --git a/src/graphql/pyutils/inspect.py b/src/graphql/pyutils/inspect.py index 8fc99dce..d3470fec 100644 --- a/src/graphql/pyutils/inspect.py +++ b/src/graphql/pyutils/inspect.py @@ -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: diff --git a/src/graphql/type/definition.py b/src/graphql/type/definition.py index dbe03ada..7ec9ed08 100644 --- a/src/graphql/type/definition.py +++ b/src/graphql/type/definition.py @@ -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, ) @@ -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): @@ -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() } @@ -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() } @@ -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): @@ -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 @@ -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() } @@ -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( @@ -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]: diff --git a/src/graphql/type/directives.py b/src/graphql/type/directives.py index 310968d1..31673c1d 100644 --- a/src/graphql/type/directives.py +++ b/src/graphql/type/directives.py @@ -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): @@ -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): diff --git a/src/graphql/type/schema.py b/src/graphql/type/schema.py index 321659c5..a2e0320d 100644 --- a/src/graphql/type/schema.py +++ b/src/graphql/type/schema.py @@ -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): @@ -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) diff --git a/src/graphql/type/validate.py b/src/graphql/type/validate.py index 555bc30d..2d639ee4 100644 --- a/src/graphql/type/validate.py +++ b/src/graphql/type/validate.py @@ -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), ) diff --git a/src/graphql/utilities/ast_to_dict.py b/src/graphql/utilities/ast_to_dict.py index 9cacd8ab..a43cf139 100644 --- a/src/graphql/utilities/ast_to_dict.py +++ b/src/graphql/utilities/ast_to_dict.py @@ -10,8 +10,7 @@ @overload def ast_to_dict( node: Node, locations: bool = False, cache: Optional[Dict[Node, Any]] = None -) -> Dict: - ... +) -> Dict: ... @overload @@ -19,8 +18,7 @@ def ast_to_dict( node: Collection[Node], locations: bool = False, cache: Optional[Dict[Node, Any]] = None, -) -> List[Node]: - ... +) -> List[Node]: ... @overload @@ -28,8 +26,7 @@ def ast_to_dict( node: OperationType, locations: bool = False, cache: Optional[Dict[Node, Any]] = None, -) -> str: - ... +) -> str: ... def ast_to_dict( diff --git a/src/graphql/utilities/extend_schema.py b/src/graphql/utilities/extend_schema.py index 93c8dce4..0a9802a9 100644 --- a/src/graphql/utilities/extend_schema.py +++ b/src/graphql/utilities/extend_schema.py @@ -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"] diff --git a/src/graphql/utilities/find_breaking_changes.py b/src/graphql/utilities/find_breaking_changes.py index 281a2def..290b9e2b 100644 --- a/src/graphql/utilities/find_breaking_changes.py +++ b/src/graphql/utilities/find_breaking_changes.py @@ -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(): @@ -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." + ), ) ) diff --git a/src/graphql/utilities/type_from_ast.py b/src/graphql/utilities/type_from_ast.py index d8f2a5be..1fdbcf22 100644 --- a/src/graphql/utilities/type_from_ast.py +++ b/src/graphql/utilities/type_from_ast.py @@ -17,27 +17,25 @@ @overload def type_from_ast( schema: GraphQLSchema, type_node: NamedTypeNode -) -> Optional[GraphQLNamedType]: - ... +) -> Optional[GraphQLNamedType]: ... @overload def type_from_ast( schema: GraphQLSchema, type_node: ListTypeNode -) -> Optional[GraphQLList]: - ... +) -> Optional[GraphQLList]: ... @overload def type_from_ast( schema: GraphQLSchema, type_node: NonNullTypeNode -) -> Optional[GraphQLNonNull]: - ... +) -> Optional[GraphQLNonNull]: ... @overload -def type_from_ast(schema: GraphQLSchema, type_node: TypeNode) -> Optional[GraphQLType]: - ... +def type_from_ast( + schema: GraphQLSchema, type_node: TypeNode +) -> Optional[GraphQLType]: ... def type_from_ast( diff --git a/src/graphql/validation/rules/known_type_names.py b/src/graphql/validation/rules/known_type_names.py index 68e10454..aa210899 100644 --- a/src/graphql/validation/rules/known_type_names.py +++ b/src/graphql/validation/rules/known_type_names.py @@ -62,9 +62,11 @@ def enter_named_type( suggested_types = suggestion_list( type_name, - list(standard_type_names) + self.type_names - if is_sdl - else self.type_names, + ( + list(standard_type_names) + self.type_names + if is_sdl + else self.type_names + ), ) self.report_error( GraphQLError( diff --git a/src/graphql/validation/rules/no_undefined_variables.py b/src/graphql/validation/rules/no_undefined_variables.py index a890473f..7e4a6873 100644 --- a/src/graphql/validation/rules/no_undefined_variables.py +++ b/src/graphql/validation/rules/no_undefined_variables.py @@ -34,10 +34,12 @@ def leave_operation_definition( if var_name not in defined_variables: self.report_error( GraphQLError( - f"Variable '${var_name}' is not defined" - f" by operation '{operation.name.value}'." - if operation.name - else f"Variable '${var_name}' is not defined.", + ( + f"Variable '${var_name}' is not defined" + f" by operation '{operation.name.value}'." + if operation.name + else f"Variable '${var_name}' is not defined." + ), [node, operation], ) ) diff --git a/src/graphql/validation/rules/no_unused_variables.py b/src/graphql/validation/rules/no_unused_variables.py index b8770944..968b0a4b 100644 --- a/src/graphql/validation/rules/no_unused_variables.py +++ b/src/graphql/validation/rules/no_unused_variables.py @@ -37,10 +37,12 @@ def leave_operation_definition( if variable_name not in variable_name_used: self.report_error( GraphQLError( - f"Variable '${variable_name}' is never used" - f" in operation '{operation.name.value}'." - if operation.name - else f"Variable '${variable_name}' is never used.", + ( + f"Variable '${variable_name}' is never used" + f" in operation '{operation.name.value}'." + if operation.name + else f"Variable '${variable_name}' is never used." + ), variable_def, ) ) diff --git a/tests/execution/test_subscribe.py b/tests/execution/test_subscribe.py index 8b1fe639..994b6fea 100644 --- a/tests/execution/test_subscribe.py +++ b/tests/execution/test_subscribe.py @@ -855,7 +855,7 @@ def resolve_message(message, _info): subscription = await subscribe(schema, document) assert isinstance(subscription, MapAsyncIterator) - assert await (anext(subscription)) == ({"newMessage": "Hello"}, None) + assert await anext(subscription) == ({"newMessage": "Hello"}, None) with raises(RuntimeError) as exc_info: await anext(subscription) diff --git a/tests/execution/test_variables.py b/tests/execution/test_variables.py index dde674c7..58fb6fb3 100644 --- a/tests/execution/test_variables.py +++ b/tests/execution/test_variables.py @@ -83,9 +83,9 @@ def field_with_input_arg(input_arg: GraphQLArgument): return GraphQLField( GraphQLString, args={"input": input_arg}, - resolve=lambda _obj, _info, **args: repr(args["input"]) - if "input" in args - else None, + resolve=lambda _obj, _info, **args: ( + repr(args["input"]) if "input" in args else None + ), ) diff --git a/tests/fixtures/__init__.py b/tests/fixtures/__init__.py index fe63e16b..3dcb8791 100644 --- a/tests/fixtures/__init__.py +++ b/tests/fixtures/__init__.py @@ -1,4 +1,5 @@ """Fixtures for graphql tests""" + import json from os.path import dirname, join diff --git a/tests/type/test_enum.py b/tests/type/test_enum.py index f85a466b..89b5a9a7 100644 --- a/tests/type/test_enum.py +++ b/tests/type/test_enum.py @@ -75,10 +75,13 @@ class Complex2: resolve=lambda _source, info, **args: # Note: this is one of the references of the internal values # which ComplexEnum allows. - complex2 if args.get("provideGoodValue") - # Note: similar object, but not the same *reference* as - # complex2 above. Enum internal values require object equality. - else Complex2() if args.get("provideBadValue") else args.get("fromEnum"), + ( + complex2 + if args.get("provideGoodValue") + # Note: similar object, but not the same *reference* as + # complex2 above. Enum internal values require object equality. + else Complex2() if args.get("provideBadValue") else args.get("fromEnum") + ), ), }, )