Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tests/execution/test_abstract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, NamedTuple
from typing import TYPE_CHECKING, Any, NamedTuple

import pytest

Expand All @@ -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."""
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
12 changes: 9 additions & 3 deletions tests/execution/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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():
Expand Down
2 changes: 2 additions & 0 deletions tests/execution/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/assert_equal_awaitables_or_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading