Skip to content

Commit 8c20a38

Browse files
committed
chore: add flake8-comprehensions
1 parent 35378d5 commit 8c20a38

14 files changed

+162
-163
lines changed

.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ select = [
44
"F", # pyflake
55
"I", # isort
66
"B", # flake8-bugbear
7+
"C4", # flake8-comprehensions
78
"UP", # pyupgrade
89
]
910

graphql_server/aiohttp/graphqlview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ async def __call__(self, request):
225225
except HttpQueryError as err:
226226
parsed_error = GraphQLError(err.message)
227227
return web.Response(
228-
body=self.encode(dict(errors=[self.format_error(parsed_error)])),
228+
body=self.encode({"errors": [self.format_error(parsed_error)]}),
229229
status=err.status_code,
230230
headers=err.headers,
231231
content_type="application/json",

graphql_server/flask/graphqlview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def dispatch_request(self):
153153
except HttpQueryError as e:
154154
parsed_error = GraphQLError(e.message)
155155
return Response(
156-
self.encode(dict(errors=[self.format_error(parsed_error)])),
156+
self.encode({"errors": [self.format_error(parsed_error)]}),
157157
status=e.status_code,
158158
headers=e.headers,
159159
content_type="application/json",

graphql_server/quart/graphqlview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async def dispatch_request(self):
169169
except HttpQueryError as e:
170170
parsed_error = GraphQLError(e.message)
171171
return Response(
172-
self.encode(dict(errors=[self.format_error(parsed_error)])),
172+
self.encode({"errors": [self.format_error(parsed_error)]}),
173173
status=e.status_code,
174174
headers=e.headers,
175175
content_type="application/json",

graphql_server/sanic/graphqlview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ async def __handle_request(self, request, *args, **kwargs):
181181
except HttpQueryError as e:
182182
parsed_error = GraphQLError(e.message)
183183
return HTTPResponse(
184-
self.encode(dict(errors=[self.format_error(parsed_error)])),
184+
self.encode({"errors": [self.format_error(parsed_error)]}),
185185
status=e.status_code,
186186
headers=e.headers,
187187
content_type="application/json",

graphql_server/webob/graphqlview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def dispatch_request(self, request):
165165
except HttpQueryError as e:
166166
parsed_error = GraphQLError(e.message)
167167
return Response(
168-
self.encode(dict(errors=[self.format_error(parsed_error)])),
168+
self.encode({"errors": [self.format_error(parsed_error)]}),
169169
status=e.status_code,
170170
charset=self.charset,
171171
headers=e.headers or {},

tests/aiohttp/test_graphqlview.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ async def test_allows_mutation_to_exist_within_a_get(client):
179179
async def test_allows_post_with_json_encoding(client):
180180
response = await client.post(
181181
"/graphql",
182-
data=json.dumps(dict(query="{test}")),
182+
data=json.dumps({"query": "{test}"}),
183183
headers={"content-type": "application/json"},
184184
)
185185

@@ -192,9 +192,9 @@ async def test_allows_sending_a_mutation_via_post(client):
192192
response = await client.post(
193193
"/graphql",
194194
data=json.dumps(
195-
dict(
196-
query="mutation TestMutation { writeTest { test } }",
197-
)
195+
{
196+
"query": "mutation TestMutation { writeTest { test } }",
197+
}
198198
),
199199
headers={"content-type": "application/json"},
200200
)
@@ -222,10 +222,10 @@ async def test_supports_post_json_query_with_string_variables(client):
222222
response = await client.post(
223223
"/graphql",
224224
data=json.dumps(
225-
dict(
226-
query="query helloWho($who: String){ test(who: $who) }",
227-
variables=json.dumps({"who": "Dolly"}),
228-
)
225+
{
226+
"query": "query helloWho($who: String){ test(who: $who) }",
227+
"variables": json.dumps({"who": "Dolly"}),
228+
}
229229
),
230230
headers={"content-type": "application/json"},
231231
)
@@ -239,10 +239,10 @@ async def test_supports_post_json_query_with_json_variables(client):
239239
response = await client.post(
240240
"/graphql",
241241
data=json.dumps(
242-
dict(
243-
query="query helloWho($who: String){ test(who: $who) }",
244-
variables={"who": "Dolly"},
245-
)
242+
{
243+
"query": "query helloWho($who: String){ test(who: $who) }",
244+
"variables": {"who": "Dolly"},
245+
}
246246
),
247247
headers={"content-type": "application/json"},
248248
)
@@ -256,10 +256,10 @@ async def test_supports_post_url_encoded_query_with_string_variables(client):
256256
response = await client.post(
257257
"/graphql",
258258
data=urlencode(
259-
dict(
260-
query="query helloWho($who: String){ test(who: $who) }",
261-
variables=json.dumps({"who": "Dolly"}),
262-
),
259+
{
260+
"query": "query helloWho($who: String){ test(who: $who) }",
261+
"variables": json.dumps({"who": "Dolly"}),
262+
},
263263
),
264264
headers={"content-type": "application/x-www-form-urlencoded"},
265265
)
@@ -273,9 +273,9 @@ async def test_supports_post_json_quey_with_get_variable_values(client):
273273
response = await client.post(
274274
url_string(variables=json.dumps({"who": "Dolly"})),
275275
data=json.dumps(
276-
dict(
277-
query="query helloWho($who: String){ test(who: $who) }",
278-
)
276+
{
277+
"query": "query helloWho($who: String){ test(who: $who) }",
278+
}
279279
),
280280
headers={"content-type": "application/json"},
281281
)
@@ -289,9 +289,9 @@ async def test_post_url_encoded_query_with_get_variable_values(client):
289289
response = await client.post(
290290
url_string(variables=json.dumps({"who": "Dolly"})),
291291
data=urlencode(
292-
dict(
293-
query="query helloWho($who: String){ test(who: $who) }",
294-
)
292+
{
293+
"query": "query helloWho($who: String){ test(who: $who) }",
294+
}
295295
),
296296
headers={"content-type": "application/x-www-form-urlencoded"},
297297
)
@@ -317,17 +317,17 @@ async def test_allows_post_with_operation_name(client):
317317
response = await client.post(
318318
"/graphql",
319319
data=json.dumps(
320-
dict(
321-
query="""
320+
{
321+
"query": """
322322
query helloYou { test(who: "You"), ...shared }
323323
query helloWorld { test(who: "World"), ...shared }
324324
query helloDolly { test(who: "Dolly"), ...shared }
325325
fragment shared on QueryRoot {
326326
shared: test(who: "Everyone")
327327
}
328328
""",
329-
operationName="helloWorld",
330-
)
329+
"operationName": "helloWorld",
330+
}
331331
),
332332
headers={"content-type": "application/json"},
333333
)
@@ -599,7 +599,7 @@ async def test_post_multipart_data(client):
599599
async def test_batch_allows_post_with_json_encoding(app, client):
600600
response = await client.post(
601601
"/graphql",
602-
data=json.dumps([dict(id=1, query="{test}")]),
602+
data=json.dumps([{"id": 1, "query": "{test}"}]),
603603
headers={"content-type": "application/json"},
604604
)
605605

@@ -614,11 +614,11 @@ async def test_batch_supports_post_json_query_with_json_variables(app, client):
614614
"/graphql",
615615
data=json.dumps(
616616
[
617-
dict(
618-
id=1,
619-
query="query helloWho($who: String){ test(who: $who) }",
620-
variables={"who": "Dolly"},
621-
)
617+
{
618+
"id": 1,
619+
"query": "query helloWho($who: String){ test(who: $who) }",
620+
"variables": {"who": "Dolly"},
621+
}
622622
]
623623
),
624624
headers={"content-type": "application/json"},
@@ -635,18 +635,18 @@ async def test_batch_allows_post_with_operation_name(app, client):
635635
"/graphql",
636636
data=json.dumps(
637637
[
638-
dict(
639-
id=1,
640-
query="""
638+
{
639+
"id": 1,
640+
"query": """
641641
query helloYou { test(who: "You"), ...shared }
642642
query helloWorld { test(who: "World"), ...shared }
643643
query helloDolly { test(who: "Dolly"), ...shared }
644644
fragment shared on QueryRoot {
645645
shared: test(who: "Everyone")
646646
}
647647
""",
648-
operationName="helloWorld",
649-
)
648+
"operationName": "helloWorld",
649+
}
650650
]
651651
),
652652
headers={"content-type": "application/json"},
@@ -694,7 +694,7 @@ async def test_preflight_incorrect_request(client):
694694
async def test_custom_execution_context_class(client):
695695
response = await client.post(
696696
"/graphql",
697-
data=json.dumps(dict(query="{test}")),
697+
data=json.dumps({"query": "{test}"}),
698698
headers={"content-type": "application/json"},
699699
)
700700

tests/flask/test_graphqlview.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def test_allows_sending_a_mutation_via_post(app, client):
192192
def test_allows_post_with_url_encoding(app, client):
193193
response = client.post(
194194
url_string(app),
195-
data=urlencode(dict(query="{test}")),
195+
data=urlencode({"query": "{test}"}),
196196
content_type="application/x-www-form-urlencoded",
197197
)
198198

@@ -232,10 +232,10 @@ def test_supports_post_url_encoded_query_with_string_variables(app, client):
232232
response = client.post(
233233
url_string(app),
234234
data=urlencode(
235-
dict(
236-
query="query helloWho($who: String){ test(who: $who) }",
237-
variables=json.dumps({"who": "Dolly"}),
238-
)
235+
{
236+
"query": "query helloWho($who: String){ test(who: $who) }",
237+
"variables": json.dumps({"who": "Dolly"}),
238+
}
239239
),
240240
content_type="application/x-www-form-urlencoded",
241241
)
@@ -261,9 +261,9 @@ def test_post_url_encoded_query_with_get_variable_values(app, client):
261261
response = client.post(
262262
url_string(app, variables=json.dumps({"who": "Dolly"})),
263263
data=urlencode(
264-
dict(
265-
query="query helloWho($who: String){ test(who: $who) }",
266-
)
264+
{
265+
"query": "query helloWho($who: String){ test(who: $who) }",
266+
}
267267
),
268268
content_type="application/x-www-form-urlencoded",
269269
)

tests/quart/test_graphqlview.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ async def test_allows_post_with_url_encoding(app: Quart, client: TestClientProto
245245
app,
246246
client,
247247
method="POST",
248-
data=urlencode(dict(query="{test}")),
248+
data=urlencode({"query": "{test}"}),
249249
headers=Headers({"Content-Type": "application/x-www-form-urlencoded"}),
250250
)
251251

@@ -303,10 +303,10 @@ async def test_supports_post_url_encoded_query_with_string_variables(
303303
client,
304304
method="POST",
305305
data=urlencode(
306-
dict(
307-
query="query helloWho($who: String){ test(who: $who) }",
308-
variables=json.dumps({"who": "Dolly"}),
309-
)
306+
{
307+
"query": "query helloWho($who: String){ test(who: $who) }",
308+
"variables": json.dumps({"who": "Dolly"}),
309+
}
310310
),
311311
headers=Headers({"Content-Type": "application/x-www-form-urlencoded"}),
312312
)
@@ -345,9 +345,9 @@ async def test_post_url_encoded_query_with_get_variable_values(
345345
client,
346346
method="POST",
347347
data=urlencode(
348-
dict(
349-
query="query helloWho($who: String){ test(who: $who) }",
350-
)
348+
{
349+
"query": "query helloWho($who: String){ test(who: $who) }",
350+
}
351351
),
352352
headers=Headers({"Content-Type": "application/x-www-form-urlencoded"}),
353353
variables=json.dumps({"who": "Dolly"}),

tests/sanic/test_graphqlview.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ def test_supports_post_url_encoded_query_with_string_variables(app):
224224
_, response = app.test_client.post(
225225
uri=url_string(),
226226
content=urlencode(
227-
dict(
228-
query="query helloWho($who: String){ test(who: $who) }",
229-
variables=json.dumps({"who": "Dolly"}),
230-
)
227+
{
228+
"query": "query helloWho($who: String){ test(who: $who) }",
229+
"variables": json.dumps({"who": "Dolly"}),
230+
}
231231
),
232232
headers={"content-type": "application/x-www-form-urlencoded"},
233233
)
@@ -253,9 +253,9 @@ def test_post_url_encoded_query_with_get_variable_values(app):
253253
_, response = app.test_client.post(
254254
uri=url_string(variables=json.dumps({"who": "Dolly"})),
255255
content=urlencode(
256-
dict(
257-
query="query helloWho($who: String){ test(who: $who) }",
258-
)
256+
{
257+
"query": "query helloWho($who: String){ test(who: $who) }",
258+
}
259259
),
260260
headers={"content-type": "application/x-www-form-urlencoded"},
261261
)
@@ -434,9 +434,9 @@ def test_handles_poorly_formed_variables(app):
434434
def test_handles_unsupported_http_methods(app):
435435
_, response = app.test_client.put(uri=url_string(query="{test}"))
436436
assert response.status == 405
437-
allowed_methods = set(
437+
allowed_methods = {
438438
method.strip() for method in response.headers["Allow"].split(",")
439-
)
439+
}
440440
assert allowed_methods in [{"GET", "POST"}, {"HEAD", "GET", "POST", "OPTIONS"}]
441441
assert response_json(response) == {
442442
"errors": [

tests/test_asyncio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_get_responses_using_asyncio_executor():
4747

4848
async def get_results():
4949
result_promises, params = run_http_query(
50-
schema, "get", {}, dict(query=query), run_sync=False
50+
schema, "get", {}, {"query": query}, run_sync=False
5151
)
5252
res = [await result for result in result_promises]
5353
return res, params

0 commit comments

Comments
 (0)