From 494d5406cf6d4db44f48e1a1dc1a5f11c11c2e36 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 23 Jul 2024 23:28:07 +0200 Subject: [PATCH] Some lint fixes (#3578) * lint * T * T --- noxfile.py | 1 - strawberry/printer/printer.py | 2 +- strawberry/relay/fields.py | 2 +- strawberry/relay/types.py | 2 +- strawberry/schema/execute.py | 8 +------- strawberry/types/lazy_type.py | 2 +- strawberry/utils/await_maybe.py | 4 ++-- strawberry/utils/typing.py | 2 +- 8 files changed, 8 insertions(+), 15 deletions(-) diff --git a/noxfile.py b/noxfile.py index 4488fcc53e..40ab7a4bd8 100644 --- a/noxfile.py +++ b/noxfile.py @@ -130,7 +130,6 @@ def tests_typecheckers(session: Session) -> None: session.install("pyright") session.install("pydantic") - session.install("git+https://github.com/python/mypy.git#master") session.run( "pytest", diff --git a/strawberry/printer/printer.py b/strawberry/printer/printer.py index e48a001a53..d5ac653251 100644 --- a/strawberry/printer/printer.py +++ b/strawberry/printer/printer.py @@ -84,7 +84,7 @@ def _serialize_dataclasses(value: object) -> object: ... def _serialize_dataclasses(value): if dataclasses.is_dataclass(value): - return dataclasses.asdict(value) + return dataclasses.asdict(value) # type: ignore if isinstance(value, (list, tuple)): return [_serialize_dataclasses(v) for v in value] if isinstance(value, dict): diff --git a/strawberry/relay/fields.py b/strawberry/relay/fields.py index 45ce8648ea..5af00700f8 100644 --- a/strawberry/relay/fields.py +++ b/strawberry/relay/fields.py @@ -155,7 +155,7 @@ async def resolve(resolved: Any = resolved_nodes) -> List[Node]: await asyncio.gather( *awaitable_nodes.values(), *( - asyncgen_to_list(nodes) + asyncgen_to_list(nodes) # type: ignore for nodes in asyncgen_nodes.values() ), ), diff --git a/strawberry/relay/types.py b/strawberry/relay/types.py index ee9feedcd5..869e017be9 100644 --- a/strawberry/relay/types.py +++ b/strawberry/relay/types.py @@ -185,7 +185,7 @@ async def resolve_node(self, info, *, required=False, ensure_type=None) -> Any: """ n_type = self.resolve_type(info) - node = cast( + node: Node | Awaitable[Node] = cast( Awaitable[Node], n_type.resolve_node( self.node_id, diff --git a/strawberry/schema/execute.py b/strawberry/schema/execute.py index 4dacbfcbae..fe1b1fb7cd 100644 --- a/strawberry/schema/execute.py +++ b/strawberry/schema/execute.py @@ -4,7 +4,6 @@ from inspect import isawaitable from typing import ( TYPE_CHECKING, - Awaitable, Callable, Iterable, List, @@ -14,7 +13,6 @@ Type, TypedDict, Union, - cast, ) from graphql import GraphQLError, parse @@ -32,7 +30,6 @@ from typing_extensions import NotRequired, Unpack from graphql import ExecutionContext as GraphQLExecutionContext - from graphql import ExecutionResult as GraphQLExecutionResult from graphql import GraphQLSchema from graphql.language import DocumentNode from graphql.validation import ASTValidationRule @@ -139,9 +136,8 @@ async def execute( ) if isawaitable(result): - result = await cast(Awaitable["GraphQLExecutionResult"], result) + result = await result - result = cast("GraphQLExecutionResult", result) execution_context.result = result # Also set errors on the execution_context so that it's easier # to access in extensions @@ -237,13 +233,11 @@ def execute_sync( ) if isawaitable(result): - result = cast(Awaitable["GraphQLExecutionResult"], result) ensure_future(result).cancel() raise RuntimeError( "GraphQL execution failed to complete synchronously." ) - result = cast("GraphQLExecutionResult", result) execution_context.result = result # Also set errors on the execution_context so that it's easier # to access in extensions diff --git a/strawberry/types/lazy_type.py b/strawberry/types/lazy_type.py index e8cc6cf9f2..776ad52d4a 100644 --- a/strawberry/types/lazy_type.py +++ b/strawberry/types/lazy_type.py @@ -58,7 +58,7 @@ def __class_getitem__(cls, params: Tuple[str, str]) -> "Self": return cls(type_name, module, package) - def __or__(self, other: Other) -> Union[Self, Other]: + def __or__(self, other: Other) -> object: return Union[self, other] def resolve_type(self) -> Type[Any]: diff --git a/strawberry/utils/await_maybe.py b/strawberry/utils/await_maybe.py index ecdfe5449c..65b1a23bd6 100644 --- a/strawberry/utils/await_maybe.py +++ b/strawberry/utils/await_maybe.py @@ -1,5 +1,5 @@ import inspect -from typing import AsyncIterator, Awaitable, Iterator, TypeVar, Union, cast +from typing import AsyncIterator, Awaitable, Iterator, TypeVar, Union T = TypeVar("T") @@ -11,7 +11,7 @@ async def await_maybe(value: AwaitableOrValue[T]) -> T: if inspect.isawaitable(value): return await value - return cast(T, value) + return value __all__ = ["await_maybe", "AwaitableOrValue", "AsyncIteratorOrIterator"] diff --git a/strawberry/utils/typing.py b/strawberry/utils/typing.py index e88d3edd92..82712f29ab 100644 --- a/strawberry/utils/typing.py +++ b/strawberry/utils/typing.py @@ -239,7 +239,7 @@ def _ast_replace_union_operation( expr = ast.Subscript( expr.value, # The cast is required for mypy on python 3.7 and 3.8 - ast.Index(_ast_replace_union_operation(cast(Any, expr.slice).value)), + ast.Index(_ast_replace_union_operation(cast(Any, expr.slice).value)), # type: ignore ast.Load(), ) elif isinstance(expr.slice, (ast.BinOp, ast.Tuple)):