Skip to content

Commit

Permalink
chore(ruff): Enable ignored UP rules
Browse files Browse the repository at this point in the history
  • Loading branch information
bellini666 committed Dec 25, 2024
1 parent e78f8c6 commit c79acee
Show file tree
Hide file tree
Showing 117 changed files with 1,117 additions and 1,224 deletions.
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,6 @@ src = ["strawberry", "tests"]
[tool.ruff.lint]
select = ["ALL"]
ignore = [
# https://github.com/astral-sh/ruff/pull/4427
# equivalent to keep-runtime-typing
"UP006",
"UP007",

"TID252",
# we use asserts in tests and to hint mypy
"S101",
Expand Down
15 changes: 7 additions & 8 deletions strawberry/aiohttp/test/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import (
TYPE_CHECKING,
Any,
Optional,
)

from strawberry.test.client import BaseGraphQLTestClient, Response
Expand All @@ -17,11 +16,11 @@ class GraphQLTestClient(BaseGraphQLTestClient):
async def query(
self,
query: str,
variables: Optional[dict[str, Mapping]] = None,
headers: Optional[dict[str, object]] = None,
asserts_errors: Optional[bool] = None,
files: Optional[dict[str, object]] = None,
assert_no_errors: Optional[bool] = True,
variables: dict[str, Mapping] | None = None,
headers: dict[str, object] | None = None,
asserts_errors: bool | None = None,
files: dict[str, object] | None = None,
assert_no_errors: bool | None = True,
) -> Response:
body = self._build_body(query, variables, files)

Expand Down Expand Up @@ -54,8 +53,8 @@ async def query(
async def request(
self,
body: dict[str, object],
headers: Optional[dict[str, object]] = None,
files: Optional[dict[str, object]] = None,
headers: dict[str, object] | None = None,
files: dict[str, object] | None = None,
) -> Any:
response = await self._client.post(
self.url,
Expand Down
15 changes: 7 additions & 8 deletions strawberry/aiohttp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
TYPE_CHECKING,
Any,
Callable,
Optional,
Union,
cast,
)
Expand Down Expand Up @@ -80,7 +79,7 @@ async def get_form_data(self) -> FormData:
return FormData(files=files, form=data)

@property
def content_type(self) -> Optional[str]:
def content_type(self) -> str | None:
return self.headers.get("content-type")


Expand Down Expand Up @@ -138,8 +137,8 @@ class GraphQLView(
def __init__(
self,
schema: BaseSchema,
graphiql: Optional[bool] = None,
graphql_ide: Optional[GraphQL_IDE] = "graphiql",
graphiql: bool | None = None,
graphql_ide: GraphQL_IDE | None = "graphiql",
allow_queries_via_get: bool = True,
keep_alive: bool = True,
keep_alive_interval: float = 1,
Expand Down Expand Up @@ -180,12 +179,12 @@ def is_websocket_request(self, request: web.Request) -> TypeGuard[web.Request]:
ws = web.WebSocketResponse(protocols=self.subscription_protocols)
return ws.can_prepare(request).ok

async def pick_websocket_subprotocol(self, request: web.Request) -> Optional[str]:
async def pick_websocket_subprotocol(self, request: web.Request) -> str | None:
ws = web.WebSocketResponse(protocols=self.subscription_protocols)
return ws.can_prepare(request).protocol

async def create_websocket_response(
self, request: web.Request, subprotocol: Optional[str]
self, request: web.Request, subprotocol: str | None
) -> web.WebSocketResponse:
protocols = [subprotocol] if subprotocol else []
ws = web.WebSocketResponse(protocols=protocols)
Expand All @@ -201,11 +200,11 @@ async def __call__(self, request: web.Request) -> web.StreamResponse:
status=e.status_code,
)

async def get_root_value(self, request: web.Request) -> Optional[RootValue]:
async def get_root_value(self, request: web.Request) -> RootValue | None:
return None

async def get_context(
self, request: web.Request, response: Union[web.Response, web.WebSocketResponse]
self, request: web.Request, response: web.Response | web.WebSocketResponse
) -> Context:
return {"request": request, "response": response} # type: ignore

Expand Down
19 changes: 9 additions & 10 deletions strawberry/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Annotated,
Any,
ForwardRef,
Optional,
TypeVar,
Union,
cast,
Expand Down Expand Up @@ -55,14 +54,14 @@ class StrawberryAnnotation:

def __init__(
self,
annotation: Union[object, str],
annotation: object | str,
*,
namespace: Optional[dict[str, Any]] = None,
namespace: dict[str, Any] | None = None,
) -> None:
self.raw_annotation = annotation
self.namespace = namespace

self.__resolve_cache__: Optional[Union[StrawberryType, type]] = None
self.__resolve_cache__: StrawberryType | type | None = None

def __eq__(self, other: object) -> bool:
if not isinstance(other, StrawberryAnnotation):
Expand All @@ -75,8 +74,8 @@ def __hash__(self) -> int:

@staticmethod
def from_annotation(
annotation: object, namespace: Optional[dict[str, Any]] = None
) -> Optional[StrawberryAnnotation]:
annotation: object, namespace: dict[str, Any] | None = None
) -> StrawberryAnnotation | None:
if annotation is None:
return None

Expand All @@ -85,7 +84,7 @@ def from_annotation(
return annotation

@property
def annotation(self) -> Union[object, str]:
def annotation(self) -> object | str:
"""Return evaluated type on success or fallback to raw (string) annotation."""
try:
return self.evaluate()
Expand All @@ -95,7 +94,7 @@ def annotation(self) -> Union[object, str]:
return self.raw_annotation

@annotation.setter
def annotation(self, value: Union[object, str]) -> None:
def annotation(self, value: object | str) -> None:
self.raw_annotation = value

self.__resolve_cache__ = None
Expand Down Expand Up @@ -124,14 +123,14 @@ def _get_type_with_args(

return evaled_type, []

def resolve(self) -> Union[StrawberryType, type]:
def resolve(self) -> StrawberryType | type:
"""Return resolved (transformed) annotation."""
if self.__resolve_cache__ is None:
self.__resolve_cache__ = self._resolve()

return self.__resolve_cache__

def _resolve(self) -> Union[StrawberryType, type]:
def _resolve(self) -> StrawberryType | type:
evaled_type = cast(Any, self.evaluate())

if is_private(evaled_type):
Expand Down
22 changes: 9 additions & 13 deletions strawberry/asgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from typing import (
TYPE_CHECKING,
Callable,
Optional,
Union,
cast,
)
from typing_extensions import TypeGuard
Expand Down Expand Up @@ -67,7 +65,7 @@ def headers(self) -> Mapping[str, str]:
return self.request.headers

@property
def content_type(self) -> Optional[str]:
def content_type(self) -> str | None:
return self.request.headers.get("content-type")

async def get_body(self) -> bytes:
Expand Down Expand Up @@ -133,8 +131,8 @@ class GraphQL(
def __init__(
self,
schema: BaseSchema,
graphiql: Optional[bool] = None,
graphql_ide: Optional[GraphQL_IDE] = "graphiql",
graphiql: bool | None = None,
graphql_ide: GraphQL_IDE | None = "graphiql",
allow_queries_via_get: bool = True,
keep_alive: bool = False,
keep_alive_interval: float = 1,
Expand Down Expand Up @@ -181,19 +179,17 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
else: # pragma: no cover
raise ValueError("Unknown scope type: {!r}".format(scope["type"]))

async def get_root_value(
self, request: Union[Request, WebSocket]
) -> Optional[RootValue]:
async def get_root_value(self, request: Request | WebSocket) -> RootValue | None:
return None

async def get_context(
self, request: Union[Request, WebSocket], response: Union[Response, WebSocket]
self, request: Request | WebSocket, response: Response | WebSocket
) -> Context:
return {"request": request, "response": response} # type: ignore

async def get_sub_response(
self,
request: Union[Request, WebSocket],
request: Request | WebSocket,
) -> Response:
sub_response = Response()
sub_response.status_code = None # type: ignore
Expand Down Expand Up @@ -240,18 +236,18 @@ async def create_streaming_response(
)

def is_websocket_request(
self, request: Union[Request, WebSocket]
self, request: Request | WebSocket
) -> TypeGuard[WebSocket]:
return request.scope["type"] == "websocket"

async def pick_websocket_subprotocol(self, request: WebSocket) -> Optional[str]:
async def pick_websocket_subprotocol(self, request: WebSocket) -> str | None:
protocols = request["subprotocols"]
intersection = set(protocols) & set(self.protocols)
sorted_intersection = sorted(intersection, key=protocols.index)
return next(iter(sorted_intersection), None)

async def create_websocket_response(
self, request: WebSocket, subprotocol: Optional[str]
self, request: WebSocket, subprotocol: str | None
) -> WebSocket:
await request.accept(subprotocol=subprotocol)
return request
10 changes: 5 additions & 5 deletions strawberry/asgi/test/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import json
from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Any

from strawberry.test import BaseGraphQLTestClient

Expand All @@ -14,8 +14,8 @@ class GraphQLTestClient(BaseGraphQLTestClient):
def _build_body(
self,
query: str,
variables: Optional[dict[str, Mapping]] = None,
files: Optional[dict[str, object]] = None,
variables: dict[str, Mapping] | None = None,
files: dict[str, object] | None = None,
) -> dict[str, object]:
body: dict[str, object] = {"query": query}

Expand All @@ -36,8 +36,8 @@ def _build_body(
def request(
self,
body: dict[str, object],
headers: Optional[dict[str, object]] = None,
files: Optional[dict[str, object]] = None,
headers: dict[str, object] | None = None,
files: dict[str, object] | None = None,
) -> Any:
return self._client.post(
self.url,
Expand Down
16 changes: 8 additions & 8 deletions strawberry/chalice/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING, Any, Optional, Union, cast
from typing import TYPE_CHECKING, Any, cast

from chalice.app import Request, Response
from strawberry.http.exceptions import HTTPException
Expand All @@ -27,7 +27,7 @@ def query_params(self) -> QueryParams:
return self.request.query_params or {}

@property
def body(self) -> Union[str, bytes]:
def body(self) -> str | bytes:
return self.request.raw_body

@property
Expand All @@ -39,15 +39,15 @@ def headers(self) -> Mapping[str, str]:
return self.request.headers

@property
def post_data(self) -> Mapping[str, Union[str, bytes]]:
def post_data(self) -> Mapping[str, str | bytes]:
raise NotImplementedError

@property
def files(self) -> Mapping[str, Any]:
raise NotImplementedError

@property
def content_type(self) -> Optional[str]:
def content_type(self) -> str | None:
return self.request.headers.get("Content-Type", None)


Expand All @@ -60,8 +60,8 @@ class GraphQLView(
def __init__(
self,
schema: BaseSchema,
graphiql: Optional[bool] = None,
graphql_ide: Optional[GraphQL_IDE] = "graphiql",
graphiql: bool | None = None,
graphql_ide: GraphQL_IDE | None = "graphiql",
allow_queries_via_get: bool = True,
) -> None:
self.allow_queries_via_get = allow_queries_via_get
Expand All @@ -76,7 +76,7 @@ def __init__(
else:
self.graphql_ide = graphql_ide

def get_root_value(self, request: Request) -> Optional[RootValue]:
def get_root_value(self, request: Request) -> RootValue | None:
return None

def render_graphql_ide(self, request: Request) -> Response:
Expand All @@ -93,7 +93,7 @@ def error_response(
message: str,
error_code: str,
http_status_code: int,
headers: Optional[dict[str, str | list[str]]] = None,
headers: dict[str, str | list[str]] | None = None,
) -> Response:
"""A wrapper for error responses.
Expand Down
Loading

0 comments on commit c79acee

Please sign in to comment.