Skip to content

Commit d60ff58

Browse files
committed
formatting and typing fixes
1 parent 8b84773 commit d60ff58

13 files changed

+84
-52
lines changed

graphql/execution/values.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_variable_values(
4040
if inputs is None:
4141
inputs = {}
4242

43-
values = {}
43+
values = {} # type: Dict[str, Any]
4444
for def_ast in definition_asts:
4545
var_name = def_ast.variable.name.value
4646
var_type = type_from_ast(schema, def_ast.type)

graphql/language/parser.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,7 @@ def parse_value_literal(parser, is_const):
509509
)
510510

511511
if token.value == "null":
512-
return ast.NullValue( # type: ignore
513-
loc=loc(parser, token.start)
514-
)
512+
return ast.NullValue(loc=loc(parser, token.start)) # type: ignore
515513

516514
return ast.EnumValue( # type: ignore
517515
value=token.value, loc=loc(parser, token.start)

graphql/language/printer.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ def leave_OperationDefinition(self, node, *args):
8383

8484
def leave_VariableDefinition(self, node, *args):
8585
# type: (Any, *Any) -> str
86-
return node.variable + ": " + node.type + wrap(" = ", node.default_value, is_default_value=True)
86+
return (
87+
node.variable
88+
+ ": "
89+
+ node.type
90+
+ wrap(" = ", node.default_value, is_default_value=True)
91+
)
8792

8893
def leave_SelectionSet(self, node, *args):
8994
# type: (Any, *Any) -> str

graphql/language/tests/test_parser.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ def test_allows_null_value():
107107

108108

109109
def test_parses_null_value_to_null():
110-
result = parse('{ fieldWithObjectInput(input: {a: null, b: null, c: "C", d: null}) }')
110+
result = parse(
111+
'{ fieldWithObjectInput(input: {a: null, b: null, c: "C", d: null}) }'
112+
)
111113
values = result.definitions[0].selection_set.selections[0].arguments[0].value.fields
112114
expected = (
113115
(u"a", ast.NullValue()),
@@ -124,7 +126,10 @@ def test_parses_null_value_in_list():
124126
assert result == ast.Document(
125127
definitions=[
126128
ast.OperationDefinition(
127-
operation="query", name=None, variable_definitions=None, directives=[],
129+
operation="query",
130+
name=None,
131+
variable_definitions=None,
132+
directives=[],
128133
selection_set=ast.SelectionSet(
129134
selections=[
130135
ast.Field(
@@ -144,7 +149,7 @@ def test_parses_null_value_in_list():
144149
ast.StringValue(value=u"A"),
145150
ast.NullValue(),
146151
ast.StringValue(value=u"C"),
147-
],
152+
]
148153
),
149154
),
150155
ast.ObjectField(
@@ -153,20 +158,23 @@ def test_parses_null_value_in_list():
153158
),
154159
]
155160
),
156-
),
161+
)
157162
],
158-
),
159-
],
163+
)
164+
]
160165
),
161-
),
162-
],
166+
)
167+
]
163168
)
164169

165170

166171
def test_null_as_name():
167172
result = parse('{ thingy(null: "stringcheese") }')
168173
assert result.definitions[0].selection_set.selections[0].name.value == "thingy"
169-
assert result.definitions[0].selection_set.selections[0].arguments[0].name.value == "null"
174+
assert (
175+
result.definitions[0].selection_set.selections[0].arguments[0].name.value
176+
== "null"
177+
)
170178

171179

172180
def test_parses_multi_byte_characters():

graphql/language/tests/test_printer.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ def test_correctly_prints_mutation_with_artifacts():
8787

8888
def test_correctly_prints_null():
8989
query_ast_shorthanded = parse('{ thingy(null: "wow", name: null) }')
90-
assert print_ast(query_ast_shorthanded) == """{
90+
assert (
91+
print_ast(query_ast_shorthanded)
92+
== """{
9193
thingy(null: "wow", name: null)
9294
}
9395
"""
96+
)
9497

9598

9699
def test_prints_kitchen_sink():

graphql/type/introspection.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,7 @@ def _resolve_default_value(input_value, *_):
541541
("type", GraphQLField(GraphQLNonNull(__Type))),
542542
(
543543
"defaultValue",
544-
GraphQLField(
545-
type=GraphQLString,
546-
resolver=_resolve_default_value,
547-
),
544+
GraphQLField(type=GraphQLString, resolver=_resolve_default_value),
548545
),
549546
]
550547
),

graphql/utils/tests/test_ast_to_code.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ def test_ast_to_code_using_kitchen_sink():
1515
def loc(start, end):
1616
return Loc(start, end, source)
1717

18-
parsed_code_ast = eval(code_ast, {}, {"ast": ast, "loc": loc, "Undefined": Undefined})
18+
parsed_code_ast = eval(
19+
code_ast, {}, {"ast": ast, "loc": loc, "Undefined": Undefined}
20+
)
1921
assert doc == parsed_code_ast

graphql/utils/tests/test_build_client_schema.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ def test_builds_a_simple_schema_with_both_operation_types():
7575
"setStringDefault": GraphQLField(
7676
GraphQLString,
7777
description="Set the string field",
78-
args={"default_value": GraphQLArgument(GraphQLString, default_value=None)},
79-
)
78+
args={
79+
"default_value": GraphQLArgument(GraphQLString, default_value=None)
80+
},
81+
),
8082
},
8183
)
8284
SubscriptionType = GraphQLObjectType(
@@ -467,7 +469,9 @@ def test_builds_a_schema_with_field_arguments_with_default_values():
467469
GraphQLField(
468470
GraphQLString,
469471
args={
470-
"intArg": GraphQLArgument(GraphQLInt, default_value=None)
472+
"intArg": GraphQLArgument(
473+
GraphQLInt, default_value=None
474+
)
471475
},
472476
),
473477
),

graphql/utils/tests/test_schema_printer.py

+28-17
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,15 @@ def test_prints_string_field_with_int_arg_with_default():
185185

186186

187187
def test_prints_string_field_with_int_arg_with_default_null():
188-
output = print_single_field_schema(GraphQLField(
189-
type=GraphQLString,
190-
args={"argOne": GraphQLArgument(GraphQLInt, default_value=None)}
191-
))
192-
assert output == """
188+
output = print_single_field_schema(
189+
GraphQLField(
190+
type=GraphQLString,
191+
args={"argOne": GraphQLArgument(GraphQLInt, default_value=None)},
192+
)
193+
)
194+
assert (
195+
output
196+
== """
193197
schema {
194198
query: Root
195199
}
@@ -198,6 +202,7 @@ def test_prints_string_field_with_int_arg_with_default_null():
198202
singleField(argOne: Int = null): String
199203
}
200204
"""
205+
)
201206

202207

203208
def test_prints_string_field_with_non_null_int_arg():
@@ -515,22 +520,24 @@ def test_prints_input_type():
515520
def test_prints_input_type_with_default():
516521
InputType = GraphQLInputObjectType(
517522
name="InputType",
518-
fields={
519-
"int": GraphQLInputObjectField(GraphQLInt, default_value=2)
520-
}
523+
fields={"int": GraphQLInputObjectField(GraphQLInt, default_value=2)},
521524
)
522525

523526
Root = GraphQLObjectType(
524527
name="Root",
525528
fields={
526-
"str": GraphQLField(GraphQLString, args={"argOne": GraphQLArgument(InputType)})
527-
}
529+
"str": GraphQLField(
530+
GraphQLString, args={"argOne": GraphQLArgument(InputType)}
531+
)
532+
},
528533
)
529534

530535
Schema = GraphQLSchema(Root)
531536
output = print_for_test(Schema)
532537

533-
assert output == """
538+
assert (
539+
output
540+
== """
534541
schema {
535542
query: Root
536543
}
@@ -543,27 +550,30 @@ def test_prints_input_type_with_default():
543550
str(argOne: InputType): String
544551
}
545552
"""
553+
)
546554

547555

548556
def test_prints_input_type_with_default_null():
549557
InputType = GraphQLInputObjectType(
550558
name="InputType",
551-
fields={
552-
"int": GraphQLInputObjectField(GraphQLInt, default_value=None)
553-
}
559+
fields={"int": GraphQLInputObjectField(GraphQLInt, default_value=None)},
554560
)
555561

556562
Root = GraphQLObjectType(
557563
name="Root",
558564
fields={
559-
"str": GraphQLField(GraphQLString, args={"argOne": GraphQLArgument(InputType)})
560-
}
565+
"str": GraphQLField(
566+
GraphQLString, args={"argOne": GraphQLArgument(InputType)}
567+
)
568+
},
561569
)
562570

563571
Schema = GraphQLSchema(Root)
564572
output = print_for_test(Schema)
565573

566-
assert output == """
574+
assert (
575+
output
576+
== """
567577
schema {
568578
query: Root
569579
}
@@ -576,6 +586,7 @@ def test_prints_input_type_with_default_null():
576586
str(argOne: InputType): String
577587
}
578588
"""
589+
)
579590

580591

581592
def test_prints_custom_scalar():

graphql/utils/value_from_ast.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ..language import ast
2-
from ..utils.undefined import Undefined
2+
from ..utils.undefined import Undefined, _Undefined
33
from ..type import (
44
GraphQLEnumType,
55
GraphQLInputObjectType,
@@ -16,7 +16,7 @@
1616

1717

1818
def value_from_ast(value_ast, type, variables=None):
19-
# type: (Optional[Node], GraphQLType, Optional[Dict[str, Union[List, Dict, int, float, bool, str, None]]]) -> Union[List, Dict, int, float, bool, str, None]
19+
# type: (Optional[Node], GraphQLType, Optional[Dict[str, Union[List, Dict, int, float, bool, str, None]]]) -> Union[List, Dict, int, float, bool, str, None, _Undefined]
2020
"""Given a type and a value AST node known to match this type, build a
2121
runtime value."""
2222
if isinstance(type, GraphQLNonNull):
@@ -25,7 +25,7 @@ def value_from_ast(value_ast, type, variables=None):
2525
return value_from_ast(value_ast, type.of_type, variables)
2626

2727
if value_ast is Undefined:
28-
return value_ast
28+
return Undefined
2929

3030
if isinstance(value_ast, ast.NullValue):
3131
return None

graphql/validation/tests/test_arguments_of_correct_type.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,16 @@ def test_good_enum_value(self):
115115
)
116116

117117
def test_null_nullable_int_value(self):
118-
expect_passes_rule(ArgumentsOfCorrectType, """
118+
expect_passes_rule(
119+
ArgumentsOfCorrectType,
120+
"""
119121
{
120122
complicatedArgs {
121123
intArgField(intArg: null)
122124
}
123125
}
124-
""")
126+
""",
127+
)
125128

126129

127130
# noinspection PyMethodMayBeStatic
@@ -247,15 +250,17 @@ def test_float_into_int(self):
247250
)
248251

249252
def test_null_into_non_null_int(self):
250-
expect_fails_rule(ArgumentsOfCorrectType, """
253+
expect_fails_rule(
254+
ArgumentsOfCorrectType,
255+
"""
251256
{
252257
complicatedArgs {
253258
nonNullIntArgField(nonNullIntArg: null)
254259
}
255260
}
256-
""", [
257-
bad_value("nonNullIntArg", "Int!", "null", 4, 51)
258-
])
261+
""",
262+
[bad_value("nonNullIntArg", "Int!", "null", 4, 51)],
263+
)
259264

260265

261266
# noinspection PyMethodMayBeStatic

graphql/validation/tests/test_default_values_of_correct_type.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_variables_with_invalid_default_values():
104104
['Expected "ComplexInput", found not an object.'],
105105
),
106106
bad_value("d", "Int!", "null", 6, 20),
107-
default_for_non_null_arg("d", "Int!", "Int", 6, 20)
107+
default_for_non_null_arg("d", "Int!", "Int", 6, 20),
108108
],
109109
)
110110

graphql/validation/tests/utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ def expect_invalid(schema, rules, query, expected_errors, sort_list=True):
295295
]
296296

297297
errors = list(map(format_error, errors))
298-
msg = ("\nexpected errors: %s"
299-
"\n got errors: %s" % (expected_errors, errors))
298+
msg = "\nexpected errors: {}\n got errors: {}".format(expected_errors, errors)
300299
if sort_list:
301300
sorted_errors = sort_lists(list(map(format_error, errors)))
302301
expected_errors = map(format_message, expected_errors)

0 commit comments

Comments
 (0)