diff --git a/tests/execution/test_abstract.py b/tests/execution/test_abstract.py index 6e9e5f15..906c5295 100644 --- a/tests/execution/test_abstract.py +++ b/tests/execution/test_abstract.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, NamedTuple +from typing import TYPE_CHECKING, Any, NamedTuple import pytest @@ -19,6 +19,9 @@ ) from graphql.utilities import build_schema +if TYPE_CHECKING: + from collections.abc import Callable + def sync_and_async(spec): """Decorator for running a test synchronously and asynchronously.""" @@ -51,6 +54,7 @@ async def execute_query( def get_is_type_of(type_, sync=True): """Get a sync or async is_type_of function for the given type.""" + is_type_of: Callable[[Any, Any], Any] if sync: def is_type_of(obj, _info): @@ -67,6 +71,7 @@ async def is_type_of(obj, _info): def get_type_error(sync=True): """Get a sync or async is_type_of or type resolver function that raises an error.""" error = RuntimeError("We are testing this error") + type_error: Callable[..., Any] if sync: def type_error(*_args): diff --git a/tests/execution/test_middleware.py b/tests/execution/test_middleware.py index 5c89a3a8..2256b8d4 100644 --- a/tests/execution/test_middleware.py +++ b/tests/execution/test_middleware.py @@ -4,7 +4,13 @@ import pytest -from graphql.execution import Middleware, MiddlewareManager, execute, subscribe +from graphql.execution import ( + ExecutionResult, + Middleware, + MiddlewareManager, + execute, + subscribe, +) from graphql.language.parser import parse from graphql.type import GraphQLField, GraphQLObjectType, GraphQLSchema, GraphQLString @@ -262,9 +268,9 @@ async def reverse_middleware(next_, value, info, **kwargs): middleware=MiddlewareManager(reverse_middleware), ) assert inspect.isasyncgen(agen) - data = (await agen.__anext__()).data + data = cast("ExecutionResult", await agen.__anext__()).data assert data == {"bar": "rab"} - data = (await agen.__anext__()).data + data = cast("ExecutionResult", await agen.__anext__()).data assert data == {"bar": "foo"} def describe_without_manager(): diff --git a/tests/execution/test_stream.py b/tests/execution/test_stream.py index 56e58779..0a113599 100644 --- a/tests/execution/test_stream.py +++ b/tests/execution/test_stream.py @@ -1691,6 +1691,7 @@ def __aiter__(self): async def __anext__(self): count = self.count self.count += 1 + name: Any if count == 1: name = throw() else: @@ -1757,6 +1758,7 @@ async def __anext__(self): raise StopAsyncIteration # pragma: no cover count = self.count self.count += 1 + name: Any if count == 1: name = throw() else: diff --git a/tests/utils/assert_equal_awaitables_or_values.py b/tests/utils/assert_equal_awaitables_or_values.py index 42e2838d..9ea69eb7 100644 --- a/tests/utils/assert_equal_awaitables_or_values.py +++ b/tests/utils/assert_equal_awaitables_or_values.py @@ -23,7 +23,7 @@ def assert_equal_awaitables_or_values(*items: T) -> T: async def assert_matching_awaitables(): return assert_matching_values(*(await asyncio.gather(*awaitable_items))) - return assert_matching_awaitables() + return cast("T", assert_matching_awaitables()) if all(not is_awaitable(item) for item in items): return assert_matching_values(*items)