From 602f7d736d7911899d7ff620abebc156eeca1dfc Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Tue, 27 Feb 2024 21:26:40 +0100 Subject: [PATCH] Fix minor issues with testing --- docs/conf.py | 2 ++ src/graphql/type/definition.py | 15 ++++++++++----- tests/execution/test_executor.py | 1 + tests/execution/test_stream.py | 1 + 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 414333bf..ce27fe29 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -141,6 +141,7 @@ ignore_references = set( """ GNT GT KT T VT +TContext enum.Enum traceback types.TracebackType @@ -166,6 +167,7 @@ graphql.execution.execute.StreamRecord graphql.language.lexer.EscapeSequence graphql.language.visitor.EnterLeaveVisitor +graphql.type.definition.TContext graphql.type.schema.InterfaceImplementations graphql.validation.validation_context.VariableUsage graphql.validation.rules.known_argument_names.KnownArgumentNamesOnDirectivesRule diff --git a/src/graphql/type/definition.py b/src/graphql/type/definition.py index 81c5612d..212ab4e6 100644 --- a/src/graphql/type/definition.py +++ b/src/graphql/type/definition.py @@ -2,7 +2,6 @@ from __future__ import annotations # Python < 3.10 -import sys from enum import Enum from typing import ( TYPE_CHECKING, @@ -555,8 +554,10 @@ def to_kwargs(self) -> GraphQLFieldKwargs: def __copy__(self) -> GraphQLField: # pragma: no cover return self.__class__(**self.to_kwargs()) -if sys.version_info < (3, 9) or sys.version_info >= (3, 11): - TContext = TypeVar("TContext") + +TContext = TypeVar("TContext") + +try: class GraphQLResolveInfo(NamedTuple, Generic[TContext]): """Collection of information passed to the resolvers. @@ -580,8 +581,11 @@ class GraphQLResolveInfo(NamedTuple, Generic[TContext]): variable_values: Dict[str, Any] context: TContext is_awaitable: Callable[[Any], bool] -else: - class GraphQLResolveInfo(NamedTuple): +except TypeError as error: # pragma: no cover + if "Multiple inheritance with NamedTuple is not supported" not in str(error): + raise # only catch expected error for Python 3.9 and 3.10 + + class GraphQLResolveInfo(NamedTuple): # type: ignore[no-redef] """Collection of information passed to the resolvers. This is always passed as the first argument to the resolvers. @@ -604,6 +608,7 @@ class GraphQLResolveInfo(NamedTuple): context: Any is_awaitable: Callable[[Any], bool] + # Note: Contrary to the Javascript implementation of GraphQLFieldResolver, # the context is passed as part of the GraphQLResolveInfo and any arguments # are passed individually as keyword arguments. diff --git a/tests/execution/test_executor.py b/tests/execution/test_executor.py index 1cbb9f0b..61f4ba62 100644 --- a/tests/execution/test_executor.py +++ b/tests/execution/test_executor.py @@ -638,6 +638,7 @@ class Data: result = execute_sync(schema, document, Data()) assert result == ({"a": "b"}, None) + @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") def uses_the_named_operation_if_operation_name_is_provided(): schema = GraphQLSchema( GraphQLObjectType("Type", {"a": GraphQLField(GraphQLString)}) diff --git a/tests/execution/test_stream.py b/tests/execution/test_stream.py index 348a70ec..a3c2e49a 100644 --- a/tests/execution/test_stream.py +++ b/tests/execution/test_stream.py @@ -373,6 +373,7 @@ async def can_disable_stream_using_if_argument(): } @pytest.mark.asyncio() + @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def does_not_disable_stream_with_null_if_argument(): document = parse( "query ($shouldStream: Boolean)"