From 04e0bb79d6a80e8bf4448ba0ac63719813177e32 Mon Sep 17 00:00:00 2001 From: brunodantas Date: Wed, 29 May 2024 23:30:09 -0300 Subject: [PATCH 1/4] replace Any --- .../handlers/graphql_transport_ws_handler.py | 9 ++++--- strawberry/annotation.py | 26 +++++++++---------- strawberry/auto.py | 6 ++--- strawberry/channels/handlers/ws_handler.py | 6 ++--- strawberry/django/views.py | 20 +++++++++----- strawberry/ext/mypy_plugin.py | 2 +- strawberry/extensions/field_extension.py | 20 +++++++++++--- strawberry/utils/logging.py | 4 +-- strawberry/utils/typing.py | 4 +-- 9 files changed, 58 insertions(+), 39 deletions(-) diff --git a/strawberry/aiohttp/handlers/graphql_transport_ws_handler.py b/strawberry/aiohttp/handlers/graphql_transport_ws_handler.py index 80ccad9a59..cbeea3bc8e 100644 --- a/strawberry/aiohttp/handlers/graphql_transport_ws_handler.py +++ b/strawberry/aiohttp/handlers/graphql_transport_ws_handler.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Callable, Dict +from typing import TYPE_CHECKING, Any, Callable, Dict, Optional from aiohttp import http, web from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL @@ -11,6 +11,7 @@ if TYPE_CHECKING: from datetime import timedelta + from strawberry.http.typevars import RootValue from strawberry.schema import BaseSchema @@ -21,7 +22,7 @@ def __init__( debug: bool, connection_init_wait_timeout: timedelta, get_context: Callable[..., Dict[str, Any]], - get_root_value: Any, + get_root_value: Callable[..., Optional[RootValue]], request: web.Request, ) -> None: super().__init__(schema, debug, connection_init_wait_timeout) @@ -30,10 +31,10 @@ def __init__( self._request = request self._ws = web.WebSocketResponse(protocols=[GRAPHQL_TRANSPORT_WS_PROTOCOL]) - async def get_context(self) -> Any: + async def get_context(self) -> Dict[str, Any]: return await self._get_context(request=self._request, response=self._ws) # type: ignore - async def get_root_value(self) -> Any: + async def get_root_value(self) -> Optional[RootValue]: return await self._get_root_value(request=self._request) async def send_json(self, data: dict) -> None: diff --git a/strawberry/annotation.py b/strawberry/annotation.py index c269ffd565..a16f741948 100644 --- a/strawberry/annotation.py +++ b/strawberry/annotation.py @@ -4,7 +4,7 @@ import sys import typing from collections import abc -from enum import Enum +from enum import Enum, EnumMeta from typing import ( TYPE_CHECKING, Any, @@ -179,13 +179,13 @@ def create_concrete_type(self, evaled_type: type) -> type: return evaled_type.__strawberry_definition__.resolve_generic(evaled_type) raise ValueError(f"Not supported {evaled_type}") - def create_enum(self, evaled_type: Any) -> EnumDefinition: + def create_enum(self, evaled_type: EnumMeta) -> EnumDefinition: try: return evaled_type._enum_definition except AttributeError: raise NotAStrawberryEnumError(evaled_type) - def create_list(self, evaled_type: Any) -> StrawberryList: + def create_list(self, evaled_type: TypeVar) -> StrawberryList: item_type, *_ = get_args(evaled_type) of_type = StrawberryAnnotation( annotation=item_type, @@ -194,7 +194,7 @@ def create_list(self, evaled_type: Any) -> StrawberryList: return StrawberryList(of_type) - def create_optional(self, evaled_type: Any) -> StrawberryOptional: + def create_optional(self, evaled_type: TypeVar) -> StrawberryOptional: types = get_args(evaled_type) non_optional_types = tuple( filter( @@ -263,7 +263,7 @@ def _is_async_type(cls, annotation: type) -> bool: return origin in ASYNC_TYPES @classmethod - def _is_enum(cls, annotation: Any) -> bool: + def _is_enum(cls, annotation: TypeVar) -> bool: # Type aliases are not types so we need to make sure annotation can go into # issubclass if not isinstance(annotation, type): @@ -271,7 +271,7 @@ def _is_enum(cls, annotation: Any) -> bool: return issubclass(annotation, Enum) @classmethod - def _is_graphql_generic(cls, annotation: Any) -> bool: + def _is_graphql_generic(cls, annotation: type) -> bool: if hasattr(annotation, "__origin__"): if definition := get_object_definition(annotation.__origin__): return definition.is_graphql_generic @@ -281,11 +281,11 @@ def _is_graphql_generic(cls, annotation: Any) -> bool: return False @classmethod - def _is_lazy_type(cls, annotation: Any) -> bool: + def _is_lazy_type(cls, annotation: TypeVar) -> bool: return isinstance(annotation, LazyType) @classmethod - def _is_optional(cls, annotation: Any, args: List[Any]) -> bool: + def _is_optional(cls, annotation: TypeVar, args: List[type]) -> bool: """Returns True if the annotation is Optional[SomeType]""" # Optionals are represented as unions @@ -298,7 +298,7 @@ def _is_optional(cls, annotation: Any, args: List[Any]) -> bool: return any(x is type(None) for x in types) @classmethod - def _is_list(cls, annotation: Any) -> bool: + def _is_list(cls, annotation: TypeVar) -> bool: """Returns True if annotation is a List""" annotation_origin = get_origin(annotation) @@ -312,7 +312,7 @@ def _is_list(cls, annotation: Any) -> bool: ) @classmethod - def _is_strawberry_type(cls, evaled_type: Any) -> bool: + def _is_strawberry_type(cls, evaled_type: TypeVar) -> bool: # Prevent import cycles from strawberry.union import StrawberryUnion @@ -339,7 +339,7 @@ def _is_strawberry_type(cls, evaled_type: Any) -> bool: return False @classmethod - def _is_union(cls, annotation: Any, args: List[Any]) -> bool: + def _is_union(cls, annotation: TypeVar, args: List[type]) -> bool: """Returns True if annotation is a Union""" # this check is needed because unions declared with the new syntax `A | B` @@ -364,7 +364,7 @@ def _is_union(cls, annotation: Any, args: List[Any]) -> bool: return any(isinstance(arg, StrawberryUnion) for arg in args) @classmethod - def _strip_async_type(cls, annotation: Type[Any]) -> type: + def _strip_async_type(cls, annotation: Type) -> type: return annotation.__args__[0] @classmethod @@ -377,7 +377,7 @@ def _strip_lazy_type(cls, annotation: LazyType[Any, Any]) -> type: ################################################################################ -def _is_input_type(type_: Any) -> bool: +def _is_input_type(type_: TypeVar) -> bool: if not has_object_definition(type_): return False diff --git a/strawberry/auto.py b/strawberry/auto.py index 5198047c4b..8fe5aa932f 100644 --- a/strawberry/auto.py +++ b/strawberry/auto.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Optional, Union, cast +from typing import Any, Dict, Optional, Union, cast from typing_extensions import Annotated, get_args, get_origin from strawberry.type import StrawberryType @@ -24,11 +24,11 @@ class StrawberryAutoMeta(type): """ - def __init__(self, *args: str, **kwargs: Any) -> None: + def __init__(self, *args: str, **kwargs: Dict[Any, Any]) -> None: self._instance: Optional[StrawberryAuto] = None super().__init__(*args, **kwargs) - def __call__(cls, *args: str, **kwargs: Any) -> Any: + def __call__(cls, *args: str, **kwargs: Dict[Any, Any]) -> StrawberryAuto: if cls._instance is None: cls._instance = super().__call__(*args, **kwargs) diff --git a/strawberry/channels/handlers/ws_handler.py b/strawberry/channels/handlers/ws_handler.py index f5fa206273..ca0e884c06 100644 --- a/strawberry/channels/handlers/ws_handler.py +++ b/strawberry/channels/handlers/ws_handler.py @@ -1,7 +1,7 @@ from __future__ import annotations import datetime -from typing import TYPE_CHECKING, Any, Optional, Sequence, Tuple, Union +from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Tuple, Union from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL @@ -102,14 +102,14 @@ async def connect(self) -> None: await self._handler.handle() return None - async def receive(self, *args: str, **kwargs: Any) -> None: + async def receive(self, *args: str, **kwargs: Dict[Any, Any]) -> None: # Overriding this so that we can pass the errors to handle_invalid_message try: await super().receive(*args, **kwargs) except ValueError as e: await self._handler.handle_invalid_message(str(e)) - async def receive_json(self, content: Any, **kwargs: Any) -> None: + async def receive_json(self, content: Any, **kwargs: Dict[Any, Any]) -> None: await self._handler.handle_message(content) async def disconnect(self, code: int) -> None: diff --git a/strawberry/django/views.py b/strawberry/django/views.py index 88fb55c267..f14ab56467 100644 --- a/strawberry/django/views.py +++ b/strawberry/django/views.py @@ -6,6 +6,8 @@ TYPE_CHECKING, Any, Callable, + Dict, + List, Mapping, Optional, Union, @@ -139,7 +141,7 @@ def __init__( graphql_ide: Optional[GraphQL_IDE] = "graphiql", allow_queries_via_get: bool = True, subscriptions_enabled: bool = False, - **kwargs: Any, + **kwargs: Dict[Any, Any], ) -> None: self.schema = schema self.allow_queries_via_get = allow_queries_via_get @@ -198,7 +200,9 @@ class GraphQLView( def get_root_value(self, request: HttpRequest) -> Optional[RootValue]: return None - def get_context(self, request: HttpRequest, response: HttpResponse) -> Any: + def get_context( + self, request: HttpRequest, response: HttpResponse + ) -> StrawberryDjangoContext: return StrawberryDjangoContext(request=request, response=response) def get_sub_response(self, request: HttpRequest) -> TemporalHttpResponse: @@ -206,7 +210,7 @@ def get_sub_response(self, request: HttpRequest) -> TemporalHttpResponse: @method_decorator(csrf_exempt) def dispatch( - self, request: HttpRequest, *args: Any, **kwargs: Any + self, request: HttpRequest, *args: List[Any], **kwargs: Dict[Any, Any] ) -> Union[HttpResponseNotAllowed, TemplateResponse, HttpResponse]: try: return self.run(request=request) @@ -245,7 +249,7 @@ class AsyncGraphQLView( request_adapter_class = AsyncDjangoHTTPRequestAdapter @classonlymethod # pyright: ignore[reportIncompatibleMethodOverride] - def as_view(cls, **initkwargs: Any) -> Callable[..., HttpResponse]: + def as_view(cls, **initkwargs: Dict[Any, Any]) -> Callable[..., HttpResponse]: # This code tells django that this view is async, see docs here: # https://docs.djangoproject.com/en/3.1/topics/async/#async-views @@ -254,10 +258,12 @@ def as_view(cls, **initkwargs: Any) -> Callable[..., HttpResponse]: return view - async def get_root_value(self, request: HttpRequest) -> Any: + async def get_root_value(self, request: HttpRequest) -> None: return None - async def get_context(self, request: HttpRequest, response: HttpResponse) -> Any: + async def get_context( + self, request: HttpRequest, response: HttpResponse + ) -> StrawberryDjangoContext: return StrawberryDjangoContext(request=request, response=response) async def get_sub_response(self, request: HttpRequest) -> TemporalHttpResponse: @@ -265,7 +271,7 @@ async def get_sub_response(self, request: HttpRequest) -> TemporalHttpResponse: @method_decorator(csrf_exempt) async def dispatch( # pyright: ignore - self, request: HttpRequest, *args: Any, **kwargs: Any + self, request: HttpRequest, *args: List[Any], **kwargs: Dict[Any, Any] ) -> Union[HttpResponseNotAllowed, TemplateResponse, HttpResponse]: try: return await self.run(request=request) diff --git a/strawberry/ext/mypy_plugin.py b/strawberry/ext/mypy_plugin.py index 849732e3da..5f58ab03e7 100644 --- a/strawberry/ext/mypy_plugin.py +++ b/strawberry/ext/mypy_plugin.py @@ -119,7 +119,7 @@ def lazy_type_analyze_callback(ctx: AnalyzeTypeContext) -> Type: return type_ -def _get_named_type(name: str, api: SemanticAnalyzerPluginInterface) -> Any: +def _get_named_type(name: str, api: SemanticAnalyzerPluginInterface) -> Instance | None: if "." in name: return api.named_type_or_none(name) diff --git a/strawberry/extensions/field_extension.py b/strawberry/extensions/field_extension.py index 15786f4e8d..ebec50981a 100644 --- a/strawberry/extensions/field_extension.py +++ b/strawberry/extensions/field_extension.py @@ -2,7 +2,7 @@ import itertools from functools import cached_property -from typing import TYPE_CHECKING, Any, Awaitable, Callable, Union +from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Union if TYPE_CHECKING: from typing_extensions import TypeAlias @@ -20,14 +20,22 @@ def apply(self, field: StrawberryField) -> None: # pragma: no cover pass def resolve( - self, next_: SyncExtensionResolver, source: Any, info: Info, **kwargs: Any + self, + next_: SyncExtensionResolver, + source: Any, + info: Info, + **kwargs: Dict[Any, Any], ) -> Any: # pragma: no cover raise NotImplementedError( "Sync Resolve is not supported for this Field Extension" ) async def resolve_async( - self, next_: AsyncExtensionResolver, source: Any, info: Info, **kwargs: Any + self, + next_: AsyncExtensionResolver, + source: Any, + info: Info, + **kwargs: Dict[Any, Any], ) -> Any: # pragma: no cover raise NotImplementedError( "Async Resolve is not supported for this Field Extension" @@ -47,7 +55,11 @@ class SyncToAsyncExtension(FieldExtension): Applied automatically""" async def resolve_async( - self, next_: AsyncExtensionResolver, source: Any, info: Info, **kwargs: Any + self, + next_: AsyncExtensionResolver, + source: Any, + info: Info, + **kwargs: Dict[Any, Any], ) -> Any: return next_(source, info, **kwargs) diff --git a/strawberry/utils/logging.py b/strawberry/utils/logging.py index d19fd49bce..6f60756ffc 100644 --- a/strawberry/utils/logging.py +++ b/strawberry/utils/logging.py @@ -1,7 +1,7 @@ from __future__ import annotations import logging -from typing import TYPE_CHECKING, Any, Optional +from typing import TYPE_CHECKING, Any, Dict, Optional if TYPE_CHECKING: from typing import Final @@ -20,6 +20,6 @@ def error( error: GraphQLError, execution_context: Optional[ExecutionContext] = None, # https://www.python.org/dev/peps/pep-0484/#arbitrary-argument-lists-and-default-argument-values - **logger_kwargs: Any, + **logger_kwargs: Dict[Any, Any], ) -> None: cls.logger.error(error, exc_info=error.original_error, **logger_kwargs) diff --git a/strawberry/utils/typing.py b/strawberry/utils/typing.py index 83ef1eff68..31c1da91d1 100644 --- a/strawberry/utils/typing.py +++ b/strawberry/utils/typing.py @@ -69,7 +69,7 @@ def get_generic_alias(type_: Type) -> Type: raise AssertionError(f"No GenericAlias available for {type_}") # pragma: no cover -def is_generic_alias(type_: Any) -> TypeGuard[_GenericAlias]: +def is_generic_alias(type_: TypeVar) -> TypeGuard[_GenericAlias]: """Returns True if the type is a generic alias.""" # _GenericAlias overrides all the methods that we can use to know if # this is a subclass of it. But if it has an "_inst" attribute @@ -323,7 +323,7 @@ def _get_namespace_from_ast( def eval_type( - type_: Any, + type_: TypeVar, globalns: Optional[Dict] = None, localns: Optional[Dict] = None, ) -> Type: From a31f23d933f7e691691f406539245c6b158cc622 Mon Sep 17 00:00:00 2001 From: brunodantas Date: Thu, 30 May 2024 12:03:21 -0300 Subject: [PATCH 2/4] fix incorrect TypeVar --- strawberry/annotation.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/strawberry/annotation.py b/strawberry/annotation.py index a16f741948..eb81298d4d 100644 --- a/strawberry/annotation.py +++ b/strawberry/annotation.py @@ -185,7 +185,7 @@ def create_enum(self, evaled_type: EnumMeta) -> EnumDefinition: except AttributeError: raise NotAStrawberryEnumError(evaled_type) - def create_list(self, evaled_type: TypeVar) -> StrawberryList: + def create_list(self, evaled_type: type) -> StrawberryList: item_type, *_ = get_args(evaled_type) of_type = StrawberryAnnotation( annotation=item_type, @@ -194,7 +194,7 @@ def create_list(self, evaled_type: TypeVar) -> StrawberryList: return StrawberryList(of_type) - def create_optional(self, evaled_type: TypeVar) -> StrawberryOptional: + def create_optional(self, evaled_type: type) -> StrawberryOptional: types = get_args(evaled_type) non_optional_types = tuple( filter( @@ -217,7 +217,7 @@ def create_optional(self, evaled_type: TypeVar) -> StrawberryOptional: return StrawberryOptional(of_type) - def create_type_var(self, evaled_type: TypeVar) -> StrawberryTypeVar: + def create_type_var(self, evaled_type: type) -> StrawberryTypeVar: return StrawberryTypeVar(evaled_type) def create_union(self, evaled_type: Type[Any], args: list[Any]) -> StrawberryUnion: @@ -263,7 +263,7 @@ def _is_async_type(cls, annotation: type) -> bool: return origin in ASYNC_TYPES @classmethod - def _is_enum(cls, annotation: TypeVar) -> bool: + def _is_enum(cls, annotation: type) -> bool: # Type aliases are not types so we need to make sure annotation can go into # issubclass if not isinstance(annotation, type): @@ -281,11 +281,11 @@ def _is_graphql_generic(cls, annotation: type) -> bool: return False @classmethod - def _is_lazy_type(cls, annotation: TypeVar) -> bool: + def _is_lazy_type(cls, annotation: type) -> bool: return isinstance(annotation, LazyType) @classmethod - def _is_optional(cls, annotation: TypeVar, args: List[type]) -> bool: + def _is_optional(cls, annotation: type, args: List[type]) -> bool: """Returns True if the annotation is Optional[SomeType]""" # Optionals are represented as unions @@ -298,7 +298,7 @@ def _is_optional(cls, annotation: TypeVar, args: List[type]) -> bool: return any(x is type(None) for x in types) @classmethod - def _is_list(cls, annotation: TypeVar) -> bool: + def _is_list(cls, annotation: type) -> bool: """Returns True if annotation is a List""" annotation_origin = get_origin(annotation) @@ -339,7 +339,7 @@ def _is_strawberry_type(cls, evaled_type: TypeVar) -> bool: return False @classmethod - def _is_union(cls, annotation: TypeVar, args: List[type]) -> bool: + def _is_union(cls, annotation: type, args: List[type]) -> bool: """Returns True if annotation is a Union""" # this check is needed because unions declared with the new syntax `A | B` From 23806261864c43de28ad762707100f4396b3ba1a Mon Sep 17 00:00:00 2001 From: brunodantas Date: Sun, 2 Jun 2024 16:09:11 -0300 Subject: [PATCH 3/4] add more annotations --- strawberry/type.py | 8 ++++---- strawberry/types/fields/resolver.py | 2 +- strawberry/types/nodes.py | 2 +- strawberry/union.py | 5 +++-- strawberry/unset.py | 4 ++-- strawberry/utils/dataclasses.py | 3 +-- strawberry/utils/debug.py | 2 +- strawberry/utils/deprecations.py | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/strawberry/type.py b/strawberry/type.py index b9a2b595e6..8845db54e4 100644 --- a/strawberry/type.py +++ b/strawberry/type.py @@ -190,7 +190,7 @@ class WithStrawberryObjectDefinition(Protocol): def has_object_definition( - obj: Any, + obj: type, ) -> TypeGuard[Type[WithStrawberryObjectDefinition]]: if hasattr(obj, "__strawberry_definition__"): return True @@ -207,7 +207,7 @@ def has_object_definition( @overload def get_object_definition( - obj: Any, + obj: object, *, strict: Literal[True], ) -> StrawberryObjectDefinition: ... @@ -215,14 +215,14 @@ def get_object_definition( @overload def get_object_definition( - obj: Any, + obj: object, *, strict: bool = False, ) -> Optional[StrawberryObjectDefinition]: ... def get_object_definition( - obj: Any, + obj: object, *, strict: bool = False, ) -> Optional[StrawberryObjectDefinition]: diff --git a/strawberry/types/fields/resolver.py b/strawberry/types/fields/resolver.py index 9e79dd7a66..1ab3a39faa 100644 --- a/strawberry/types/fields/resolver.py +++ b/strawberry/types/fields/resolver.py @@ -197,7 +197,7 @@ def __init__( """ # TODO: Use this when doing the actual resolving? How to deal with async resolvers? - def __call__(self, *args: str, **kwargs: Any) -> T: + def __call__(self, *args: str, **kwargs: Dict) -> T: if not callable(self.wrapped_func): raise UncallableResolverError(self) return self.wrapped_func(*args, **kwargs) diff --git a/strawberry/types/nodes.py b/strawberry/types/nodes.py index fc54c3f141..8216c4b324 100644 --- a/strawberry/types/nodes.py +++ b/strawberry/types/nodes.py @@ -32,7 +32,7 @@ Selection = Union["SelectedField", "FragmentSpread", "InlineFragment"] -def convert_value(info: GraphQLResolveInfo, node: GQLValueNode) -> Any: +def convert_value(info: GraphQLResolveInfo, node: GQLValueNode) -> object: """Return useful value from any node.""" if isinstance(node, GQLVariableNode): # Look up variable diff --git a/strawberry/union.py b/strawberry/union.py index f0a319a5a9..0339e7ac0a 100644 --- a/strawberry/union.py +++ b/strawberry/union.py @@ -8,6 +8,7 @@ TYPE_CHECKING, Any, Collection, + Dict, Iterable, List, Mapping, @@ -159,7 +160,7 @@ def copy_with( description=self.description, ) - def __call__(self, *args: str, **kwargs: Any) -> NoReturn: + def __call__(self, *args: str, **kwargs: Dict) -> NoReturn: """Do not use. Used to bypass @@ -169,7 +170,7 @@ def __call__(self, *args: str, **kwargs: Any) -> NoReturn: def get_type_resolver(self, type_map: TypeMap) -> GraphQLTypeResolver: def _resolve_union_type( - root: Any, info: GraphQLResolveInfo, type_: GraphQLAbstractType + root: type, info: GraphQLResolveInfo, type_: GraphQLAbstractType ) -> str: assert isinstance(type_, GraphQLUnionType) diff --git a/strawberry/unset.py b/strawberry/unset.py index 6a3444ce30..24748e757b 100644 --- a/strawberry/unset.py +++ b/strawberry/unset.py @@ -30,12 +30,12 @@ def __bool__(self) -> bool: UNSET: Any = UnsetType() -def _deprecated_is_unset(value: Any) -> bool: +def _deprecated_is_unset(value: object) -> bool: warnings.warn(DEPRECATED_NAMES["is_unset"], DeprecationWarning, stacklevel=2) return value is UNSET -def __getattr__(name: str) -> Any: +def __getattr__(name: str) -> object: if name in DEPRECATED_NAMES: warnings.warn(DEPRECATED_NAMES[name], DeprecationWarning, stacklevel=2) return globals()[f"_deprecated_{name}"] diff --git a/strawberry/utils/dataclasses.py b/strawberry/utils/dataclasses.py index 62e835f6e8..038356add9 100644 --- a/strawberry/utils/dataclasses.py +++ b/strawberry/utils/dataclasses.py @@ -8,12 +8,11 @@ _POST_INIT_NAME, _set_new_attribute, ) -from typing import Any from strawberry.ext.dataclasses.dataclasses import dataclass_init_fn -def add_custom_init_fn(cls: Any) -> None: +def add_custom_init_fn(cls: object) -> None: fields = [ f for f in getattr(cls, _FIELDS).values() diff --git a/strawberry/utils/debug.py b/strawberry/utils/debug.py index 1a59086fb3..0734dd42d5 100644 --- a/strawberry/utils/debug.py +++ b/strawberry/utils/debug.py @@ -5,7 +5,7 @@ class StrawberryJSONEncoder(JSONEncoder): - def default(self, o: Any) -> Any: + def default(self, o: object) -> str: return repr(o) diff --git a/strawberry/utils/deprecations.py b/strawberry/utils/deprecations.py index aa722c92d6..b4c30746e5 100644 --- a/strawberry/utils/deprecations.py +++ b/strawberry/utils/deprecations.py @@ -1,7 +1,7 @@ from __future__ import annotations import warnings -from typing import Any, Optional, Type +from typing import Optional, Type class DEPRECATION_MESSAGES: @@ -19,7 +19,7 @@ def __init__(self, msg: str, alias: object, attr_name: str) -> None: def warn(self) -> None: warnings.warn(self.msg, stacklevel=2) - def __get__(self, obj: Optional[object], type: Optional[Type] = None) -> Any: + def __get__(self, obj: Optional[object], type: Optional[Type] = None) -> object: self.warn() return self.alias From e147cf8cdb0db6c08374e045acb89c6a4fe7fb09 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 2 Jun 2024 19:09:32 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strawberry/type.py | 1 - 1 file changed, 1 deletion(-) diff --git a/strawberry/type.py b/strawberry/type.py index 8845db54e4..73e0744f57 100644 --- a/strawberry/type.py +++ b/strawberry/type.py @@ -3,7 +3,6 @@ from abc import ABC, abstractmethod from typing import ( TYPE_CHECKING, - Any, ClassVar, List, Mapping,