Skip to content

Commit 437d665

Browse files
committed
chore(deps): update ruff to 0.12.0
1 parent 74c2cef commit 437d665

File tree

111 files changed

+1075
-1127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1075
-1127
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.11.13
3+
rev: v0.12.1
44
hooks:
55
- id: ruff-format
66
exclude: ^tests/\w+/snapshots/

poetry.lock

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ packages = [{ include = "strawberry" }]
6767
include = ["strawberry/py.typed"]
6868

6969
[tool.poetry.group.dev.dependencies]
70-
ruff = "^0.11.4"
70+
ruff = "^0.12.1"
7171
asgiref = "^3.2"
7272
email-validator = { version = ">=1.1.3,<3.0.0", optional = false }
7373
freezegun = "^1.2.1"
@@ -209,6 +209,7 @@ exclude = [
209209
"node_modules",
210210
"venv",
211211
"tests/*/snapshots",
212+
"tests/python_312/*", # Ruff gives a SyntaxError because of new syntax not supported by Python 3.9
212213
]
213214
src = ["strawberry", "tests"]
214215

@@ -267,6 +268,9 @@ ignore = [
267268
# Do not force adding _co to covariant typevars
268269
"PLC0105",
269270

271+
# Allow imports inside functions, we have a lot of those
272+
"PLC0415",
273+
270274
# Allow private access to attributes
271275
"SLF001",
272276

@@ -348,6 +352,7 @@ ignore = [
348352
"PLR2004",
349353
"PLW0603",
350354
"PT011",
355+
"PT030",
351356
"RUF012",
352357
"S105",
353358
"S106",

strawberry/aiohttp/test/client.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import (
55
TYPE_CHECKING,
66
Any,
7-
Optional,
87
)
98

109
from strawberry.test.client import BaseGraphQLTestClient, Response
@@ -17,11 +16,11 @@ class GraphQLTestClient(BaseGraphQLTestClient):
1716
async def query(
1817
self,
1918
query: str,
20-
variables: Optional[dict[str, Mapping]] = None,
21-
headers: Optional[dict[str, object]] = None,
22-
asserts_errors: Optional[bool] = None,
23-
files: Optional[dict[str, object]] = None,
24-
assert_no_errors: Optional[bool] = True,
19+
variables: dict[str, Mapping] | None = None,
20+
headers: dict[str, object] | None = None,
21+
asserts_errors: bool | None = None,
22+
files: dict[str, object] | None = None,
23+
assert_no_errors: bool | None = True,
2524
) -> Response:
2625
body = self._build_body(query, variables, files)
2726

@@ -54,8 +53,8 @@ async def query(
5453
async def request(
5554
self,
5655
body: dict[str, object],
57-
headers: Optional[dict[str, object]] = None,
58-
files: Optional[dict[str, object]] = None,
56+
headers: dict[str, object] | None = None,
57+
files: dict[str, object] | None = None,
5958
) -> Any:
6059
return await self._client.post(
6160
self.url,

strawberry/aiohttp/views.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
TYPE_CHECKING,
1010
Any,
1111
Callable,
12-
Optional,
1312
Union,
1413
cast,
1514
)
@@ -80,7 +79,7 @@ async def get_form_data(self) -> FormData:
8079
return FormData(files=files, form=data)
8180

8281
@property
83-
def content_type(self) -> Optional[str]:
82+
def content_type(self) -> str | None:
8483
return self.headers.get("content-type")
8584

8685

@@ -138,8 +137,8 @@ class GraphQLView(
138137
def __init__(
139138
self,
140139
schema: BaseSchema,
141-
graphiql: Optional[bool] = None,
142-
graphql_ide: Optional[GraphQL_IDE] = "graphiql",
140+
graphiql: bool | None = None,
141+
graphql_ide: GraphQL_IDE | None = "graphiql",
143142
allow_queries_via_get: bool = True,
144143
keep_alive: bool = True,
145144
keep_alive_interval: float = 1,
@@ -180,12 +179,12 @@ def is_websocket_request(self, request: web.Request) -> TypeGuard[web.Request]:
180179
ws = web.WebSocketResponse(protocols=self.subscription_protocols)
181180
return ws.can_prepare(request).ok
182181

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

187186
async def create_websocket_response(
188-
self, request: web.Request, subprotocol: Optional[str]
187+
self, request: web.Request, subprotocol: str | None
189188
) -> web.WebSocketResponse:
190189
protocols = [subprotocol] if subprotocol else []
191190
ws = web.WebSocketResponse(protocols=protocols)
@@ -201,7 +200,7 @@ async def __call__(self, request: web.Request) -> web.StreamResponse:
201200
status=e.status_code,
202201
)
203202

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

207206
async def get_context(

strawberry/annotation.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
Annotated,
1111
Any,
1212
ForwardRef,
13-
Optional,
1413
TypeVar,
1514
Union,
1615
cast,
@@ -59,12 +58,12 @@ def __init__(
5958
self,
6059
annotation: Union[object, str],
6160
*,
62-
namespace: Optional[dict[str, Any]] = None,
61+
namespace: dict[str, Any] | None = None,
6362
) -> None:
6463
self.raw_annotation = annotation
6564
self.namespace = namespace
6665

67-
self.__resolve_cache__: Optional[Union[StrawberryType, type]] = None
66+
self.__resolve_cache__: Union[StrawberryType, type] | None = None
6867

6968
def __eq__(self, other: object) -> bool:
7069
if not isinstance(other, StrawberryAnnotation):
@@ -77,8 +76,8 @@ def __hash__(self) -> int:
7776

7877
@staticmethod
7978
def from_annotation(
80-
annotation: object, namespace: Optional[dict[str, Any]] = None
81-
) -> Optional[StrawberryAnnotation]:
79+
annotation: object, namespace: dict[str, Any] | None = None
80+
) -> StrawberryAnnotation | None:
8281
if annotation is None:
8382
return None
8483

strawberry/asgi/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import (
77
TYPE_CHECKING,
88
Callable,
9-
Optional,
109
Union,
1110
cast,
1211
)
@@ -67,7 +66,7 @@ def headers(self) -> Mapping[str, str]:
6766
return self.request.headers
6867

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

7372
async def get_body(self) -> bytes:
@@ -133,8 +132,8 @@ class GraphQL(
133132
def __init__(
134133
self,
135134
schema: BaseSchema,
136-
graphiql: Optional[bool] = None,
137-
graphql_ide: Optional[GraphQL_IDE] = "graphiql",
135+
graphiql: bool | None = None,
136+
graphql_ide: GraphQL_IDE | None = "graphiql",
138137
allow_queries_via_get: bool = True,
139138
keep_alive: bool = False,
140139
keep_alive_interval: float = 1,
@@ -183,7 +182,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
183182

184183
async def get_root_value(
185184
self, request: Union[Request, WebSocket]
186-
) -> Optional[RootValue]:
185+
) -> RootValue | None:
187186
return None
188187

189188
async def get_context(
@@ -244,14 +243,14 @@ def is_websocket_request(
244243
) -> TypeGuard[WebSocket]:
245244
return request.scope["type"] == "websocket"
246245

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

253252
async def create_websocket_response(
254-
self, request: WebSocket, subprotocol: Optional[str]
253+
self, request: WebSocket, subprotocol: str | None
255254
) -> WebSocket:
256255
await request.accept(subprotocol=subprotocol)
257256
return request

strawberry/asgi/test/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import json
4-
from typing import TYPE_CHECKING, Any, Optional
4+
from typing import TYPE_CHECKING, Any
55

66
from strawberry.test import BaseGraphQLTestClient
77

@@ -14,8 +14,8 @@ class GraphQLTestClient(BaseGraphQLTestClient):
1414
def _build_body(
1515
self,
1616
query: str,
17-
variables: Optional[dict[str, Mapping]] = None,
18-
files: Optional[dict[str, object]] = None,
17+
variables: dict[str, Mapping] | None = None,
18+
files: dict[str, object] | None = None,
1919
) -> dict[str, object]:
2020
body: dict[str, object] = {"query": query}
2121

@@ -36,8 +36,8 @@ def _build_body(
3636
def request(
3737
self,
3838
body: dict[str, object],
39-
headers: Optional[dict[str, object]] = None,
40-
files: Optional[dict[str, object]] = None,
39+
headers: dict[str, object] | None = None,
40+
files: dict[str, object] | None = None,
4141
) -> Any:
4242
return self._client.post(
4343
self.url,

strawberry/chalice/views.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import warnings
4-
from typing import TYPE_CHECKING, Any, Optional, Union, cast
4+
from typing import TYPE_CHECKING, Any, Union, cast
55

66
from chalice.app import Request, Response
77
from strawberry.http.exceptions import HTTPException
@@ -47,7 +47,7 @@ def files(self) -> Mapping[str, Any]:
4747
raise NotImplementedError
4848

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

5353

@@ -60,8 +60,8 @@ class GraphQLView(
6060
def __init__(
6161
self,
6262
schema: BaseSchema,
63-
graphiql: Optional[bool] = None,
64-
graphql_ide: Optional[GraphQL_IDE] = "graphiql",
63+
graphiql: bool | None = None,
64+
graphql_ide: GraphQL_IDE | None = "graphiql",
6565
allow_queries_via_get: bool = True,
6666
) -> None:
6767
self.allow_queries_via_get = allow_queries_via_get
@@ -76,7 +76,7 @@ def __init__(
7676
else:
7777
self.graphql_ide = graphql_ide
7878

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

8282
def render_graphql_ide(self, request: Request) -> Response:
@@ -93,7 +93,7 @@ def error_response(
9393
message: str,
9494
error_code: str,
9595
http_status_code: int,
96-
headers: Optional[dict[str, str | list[str]]] = None,
96+
headers: dict[str, str | list[str]] | None = None,
9797
) -> Response:
9898
"""A wrapper for error responses.
9999

0 commit comments

Comments
 (0)