-
-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ANN401: Replace Any #3526
base: main
Are you sure you want to change the base?
ANN401: Replace Any #3526
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kwargs are implicitly marked as dicts 😊 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm should we keep the Dict annotations? Ruff complained about the Any. |
||
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) | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider using Using
Suggested change
|
||||||
) -> None: | ||||||
self.schema = schema | ||||||
self.allow_queries_via_get = allow_queries_via_get | ||||||
|
@@ -198,15 +200,17 @@ 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: | ||||||
return 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,18 +258,20 @@ 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: | ||||||
return 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) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider using Using
Suggested change
|
||||||
) -> 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) | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmh, I think we don't need Optional here 🤔 (same below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added Optional because of this implementation, is it wrong?
strawberry/strawberry/channels/handlers/ws_handler.py
Lines 118 to 119 in 2f02b49