Skip to content

Commit 7b3f8c0

Browse files
committed
chore: fix mypy issues
1 parent 1afbb62 commit 7b3f8c0

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

graphql_server/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import six
1515

16-
from promise import promisify, is_thenable
16+
from promise import promisify, is_thenable, Promise
1717

1818
from graphql import get_default_backend
1919
from graphql.error import format_error as default_format_error
@@ -266,6 +266,7 @@ def execute_graphql_request(
266266
backend=None, # type: GraphQLBackend
267267
**kwargs # type: Any
268268
):
269+
# type: (...) -> ExecutionResult
269270
"""Execute a GraphQL request and return an ExecutionResult.
270271
271272
You need to pass the GraphQL schema and the GraphQLParams that you can get
@@ -318,18 +319,18 @@ def get_response(
318319
allow_only_query=False, # type: bool
319320
**kwargs # type: Any
320321
):
321-
# type: (...) -> Optional[ExecutionResult]
322+
# type: (...) -> Optional[Union[ExecutionResult, Promise[ExecutionResult]]]
322323
"""Get an individual execution result as response, with option to catch errors.
323324
324325
This does the same as execute_graphql_request() except that you can catch errors
325326
that belong to an exception class that you need to pass as a parameter.
326327
"""
328+
# Note: PyCharm will display a error due to the triple dot being used on Callable.
329+
execute = execute_graphql_request # type: Callable[..., Union[Promise[ExecutionResult], ExecutionResult]]
330+
if kwargs.get("return_promise", False):
331+
execute = execute_graphql_request_as_promise
332+
327333
# noinspection PyBroadException
328-
execute = (
329-
execute_graphql_request_as_promise
330-
if kwargs.get("return_promise", False)
331-
else execute_graphql_request
332-
)
333334
try:
334335
execution_result = execute(schema, params, allow_only_query, **kwargs)
335336
except catch_exc:
@@ -350,11 +351,10 @@ def format_execution_result(
350351
"""
351352
status_code = 200
352353

354+
response = None
353355
if execution_result:
354356
if execution_result.invalid:
355357
status_code = 400
356358
response = execution_result.to_dict(format_error=format_error)
357-
else:
358-
response = None
359359

360360
return FormattedResult(response, status_code)

tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[tox]
22
envlist =
3-
black,flake8,import-order,mypy,manifest
4-
py{27,35,36,37,38,39-dev,py,py3}
3+
black,flake8,import-order,mypy,manifest,py{27,35,36,37,38,39-dev,py,py3}
54
; requires = tox-conda
65

76
[testenv]

0 commit comments

Comments
 (0)