@@ -252,7 +252,7 @@ def build_response(
252252 """
253253 if self .is_awaitable (data ):
254254
255- async def build_response_async ():
255+ async def build_response_async () -> ExecutionResult :
256256 return self .build_response (await data ) # type: ignore
257257
258258 return build_response_async ()
@@ -285,6 +285,7 @@ def execute_operation(
285285 #
286286 # Similar to complete_value_catching_error.
287287 try :
288+ # noinspection PyArgumentList
288289 result = (
289290 self .execute_fields_serially
290291 if operation .operation == OperationType .MUTATION
@@ -296,7 +297,7 @@ def execute_operation(
296297 else :
297298 if self .is_awaitable (result ):
298299 # noinspection PyShadowingNames
299- async def await_result ():
300+ async def await_result () -> Any :
300301 try :
301302 return await result # type: ignore
302303 except GraphQLError as error :
@@ -316,7 +317,7 @@ def execute_fields_serially(
316317
317318 Implements the "Evaluating selection sets" section of the spec for "write" mode.
318319 """
319- results : Dict [str , Any ] = {}
320+ results : AwaitableOrValue [ Dict [str , Any ] ] = {}
320321 is_awaitable = self .is_awaitable
321322 for response_name , field_nodes in fields .items ():
322323 field_path = Path (path , response_name )
@@ -327,30 +328,36 @@ def execute_fields_serially(
327328 continue
328329 if is_awaitable (results ):
329330 # noinspection PyShadowingNames
330- async def await_and_set_result (results , response_name , result ):
331+ async def await_and_set_result (
332+ results : Awaitable [Dict [str , Any ]],
333+ response_name : str ,
334+ result : AwaitableOrValue [Any ],
335+ ) -> Dict [str , Any ]:
331336 awaited_results = await results
332337 awaited_results [response_name ] = (
333338 await result if is_awaitable (result ) else result
334339 )
335340 return awaited_results
336341
337- # noinspection PyTypeChecker
338342 results = await_and_set_result (
339343 cast (Awaitable , results ), response_name , result
340344 )
341345 elif is_awaitable (result ):
342346 # noinspection PyShadowingNames
343- async def set_result (results , response_name , result ):
347+ async def set_result (
348+ results : Dict [str , Any ], response_name : str , result : Awaitable ,
349+ ) -> Dict [str , Any ]:
344350 results [response_name ] = await result
345351 return results
346352
347- # noinspection PyTypeChecker
348- results = set_result (results , response_name , result )
353+ results = set_result (
354+ cast (Dict [str , Any ], results ), response_name , result
355+ )
349356 else :
350- results [response_name ] = result
357+ cast ( Dict [ str , Any ], results ) [response_name ] = result
351358 if is_awaitable (results ):
352359 # noinspection PyShadowingNames
353- async def get_results ():
360+ async def get_results () -> Any :
354361 return await cast (Awaitable , results )
355362
356363 return get_results ()
@@ -389,7 +396,7 @@ def execute_fields(
389396 # field, which is possibly a coroutine object. Return a coroutine object that
390397 # will yield this same map, but with any coroutines awaited in parallel and
391398 # replaced with the values they yielded.
392- async def get_results ():
399+ async def get_results () -> Dict [ str , Any ] :
393400 results .update (
394401 zip (
395402 awaitable_fields ,
@@ -579,7 +586,7 @@ def resolve_field_value_or_error(
579586 result = resolve_fn (source , info , ** args )
580587 if self .is_awaitable (result ):
581588 # noinspection PyShadowingNames
582- async def await_result ():
589+ async def await_result () -> Any :
583590 try :
584591 return await result
585592 except GraphQLError as error :
@@ -607,10 +614,11 @@ def complete_value_catching_error(
607614 This is a small wrapper around completeValue which detects and logs errors in
608615 the execution context.
609616 """
617+ completed : AwaitableOrValue [Any ]
610618 try :
611619 if self .is_awaitable (result ):
612620
613- async def await_result ():
621+ async def await_result () -> Any :
614622 value = self .complete_value (
615623 return_type , field_nodes , info , path , await result
616624 )
@@ -625,7 +633,7 @@ async def await_result():
625633 )
626634 if self .is_awaitable (completed ):
627635 # noinspection PyShadowingNames
628- async def await_completed ():
636+ async def await_completed () -> Any :
629637 try :
630638 return await completed
631639 except Exception as error :
@@ -783,7 +791,7 @@ def complete_list_value(
783791 return completed_results
784792
785793 # noinspection PyShadowingNames
786- async def get_completed_results ():
794+ async def get_completed_results () -> Any :
787795 for index , result in zip (
788796 awaitable_indices ,
789797 await gather (
@@ -828,7 +836,7 @@ def complete_abstract_value(
828836
829837 if self .is_awaitable (runtime_type ):
830838
831- async def await_complete_object_value ():
839+ async def await_complete_object_value () -> Any :
832840 value = self .complete_object_value (
833841 self .ensure_valid_runtime_type (
834842 await runtime_type , # type: ignore
@@ -912,14 +920,14 @@ def complete_object_value(
912920
913921 if self .is_awaitable (is_type_of ):
914922
915- async def collect_and_execute_subfields_async ():
923+ async def collect_and_execute_subfields_async () -> Dict [ str , Any ] :
916924 if not await is_type_of : # type: ignore
917925 raise invalid_return_type_error (
918926 return_type , result , field_nodes
919927 )
920928 return self .collect_and_execute_subfields (
921929 return_type , field_nodes , path , result
922- )
930+ ) # type: ignore
923931
924932 return collect_and_execute_subfields_async ()
925933
@@ -1158,11 +1166,12 @@ def default_type_resolver(
11581166
11591167 if awaitable_is_type_of_results :
11601168 # noinspection PyShadowingNames
1161- async def get_type ():
1169+ async def get_type () -> Optional [ Union [ GraphQLObjectType , str ]] :
11621170 is_type_of_results = await gather (* awaitable_is_type_of_results )
11631171 for is_type_of_result , type_ in zip (is_type_of_results , awaitable_types ):
11641172 if is_type_of_result :
11651173 return type_
1174+ return None
11661175
11671176 return get_type ()
11681177
0 commit comments