From 7a7506a8ce6c298d8829a198a41bcf34d196d7eb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Oct 2025 16:34:38 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.12.10 → v0.14.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.12.10...v0.14.0) - [github.com/adamchainz/blacken-docs: 1.19.1 → 1.20.0](https://github.com/adamchainz/blacken-docs/compare/1.19.1...1.20.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4d06f54154..9f7136bde0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.12.10 + rev: v0.14.0 hooks: - id: ruff-format exclude: ^tests/\w+/snapshots/ @@ -31,7 +31,7 @@ repos: args: ["--branch", "main"] - repo: https://github.com/adamchainz/blacken-docs - rev: 1.19.1 + rev: 1.20.0 hooks: - id: blacken-docs args: [--skip-errors] From 4eca83a816034539529eff4aa1a6283c529c0c3a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Oct 2025 16:35:00 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strawberry/chalice/views.py | 2 +- strawberry/channels/handlers/http_handler.py | 4 ++-- strawberry/channels/router.py | 3 +-- strawberry/channels/testing.py | 2 +- strawberry/fastapi/router.py | 6 +++--- strawberry/federation/field.py | 2 +- strawberry/flask/views.py | 1 + strawberry/litestar/controller.py | 19 ++++++++++--------- strawberry/quart/views.py | 3 ++- strawberry/relay/fields.py | 2 +- strawberry/sanic/context.py | 1 + strawberry/sanic/views.py | 2 +- strawberry/types/field.py | 2 +- strawberry/types/mutation.py | 4 ++-- tests/fastapi/test_context.py | 20 +++++++++++++------- tests/http/clients/aiohttp.py | 3 ++- tests/http/clients/chalice.py | 1 + tests/http/clients/fastapi.py | 3 ++- tests/http/clients/litestar.py | 3 ++- tests/http/clients/quart.py | 2 +- tests/http/clients/sanic.py | 3 ++- tests/litestar/app.py | 3 ++- tests/litestar/conftest.py | 2 ++ tests/litestar/test_context.py | 14 ++++++++++---- tests/litestar/test_response_headers.py | 6 ++++-- tests/litestar/test_response_status.py | 6 ++++-- tests/sanic/test_file_upload.py | 1 + tests/test/conftest.py | 3 ++- 28 files changed, 76 insertions(+), 47 deletions(-) diff --git a/strawberry/chalice/views.py b/strawberry/chalice/views.py index 7c2449c632..c4a2193511 100644 --- a/strawberry/chalice/views.py +++ b/strawberry/chalice/views.py @@ -3,9 +3,9 @@ import warnings from typing import TYPE_CHECKING, Optional, Union +from chalice.app import Request, Response from lia import ChaliceHTTPRequestAdapter, HTTPException -from chalice.app import Request, Response from strawberry.http.sync_base_view import SyncBaseHTTPView from strawberry.http.temporal_response import TemporalResponse from strawberry.http.typevars import Context, RootValue diff --git a/strawberry/channels/handlers/http_handler.py b/strawberry/channels/handlers/http_handler.py index 4f1d46c1ed..4247b57449 100644 --- a/strawberry/channels/handlers/http_handler.py +++ b/strawberry/channels/handlers/http_handler.py @@ -9,13 +9,13 @@ from typing_extensions import TypeGuard, assert_never from urllib.parse import parse_qs +from channels.db import database_sync_to_async +from channels.generic.http import AsyncHttpConsumer from django.conf import settings from django.core.files import uploadhandler from django.http.multipartparser import MultiPartParser from lia import AsyncHTTPRequestAdapter, FormData, HTTPException, SyncHTTPRequestAdapter -from channels.db import database_sync_to_async -from channels.generic.http import AsyncHttpConsumer from strawberry.http.async_base_view import AsyncBaseHTTPView from strawberry.http.sync_base_view import SyncBaseHTTPView from strawberry.http.temporal_response import TemporalResponse diff --git a/strawberry/channels/router.py b/strawberry/channels/router.py index 414902cd40..f3664c1d54 100644 --- a/strawberry/channels/router.py +++ b/strawberry/channels/router.py @@ -9,9 +9,8 @@ from typing import TYPE_CHECKING, Optional -from django.urls import re_path - from channels.routing import ProtocolTypeRouter, URLRouter +from django.urls import re_path from .handlers.http_handler import GraphQLHTTPConsumer from .handlers.ws_handler import GraphQLWSConsumer diff --git a/strawberry/channels/testing.py b/strawberry/channels/testing.py index f1807ca52b..b464f9cd4d 100644 --- a/strawberry/channels/testing.py +++ b/strawberry/channels/testing.py @@ -8,9 +8,9 @@ Union, ) +from channels.testing.websocket import WebsocketCommunicator from graphql import GraphQLError, GraphQLFormattedError -from channels.testing.websocket import WebsocketCommunicator from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL from strawberry.subscriptions.protocols.graphql_transport_ws import ( types as transport_ws_types, diff --git a/strawberry/fastapi/router.py b/strawberry/fastapi/router.py index 5b0af0978d..0d4008fc20 100644 --- a/strawberry/fastapi/router.py +++ b/strawberry/fastapi/router.py @@ -13,6 +13,9 @@ ) from typing_extensions import TypeGuard +from fastapi.datastructures import Default +from fastapi.routing import APIRoute +from fastapi.utils import generate_unique_id from lia import HTTPException, StarletteRequestAdapter from starlette import status from starlette.background import BackgroundTasks # noqa: TC002 @@ -27,9 +30,6 @@ from starlette.websockets import WebSocket from fastapi import APIRouter, Depends, params -from fastapi.datastructures import Default -from fastapi.routing import APIRoute -from fastapi.utils import generate_unique_id from strawberry.asgi import ASGIWebSocketAdapter from strawberry.exceptions import InvalidCustomContext from strawberry.fastapi.context import BaseContext, CustomContext diff --git a/strawberry/federation/field.py b/strawberry/federation/field.py index 9fbe875505..8dfb72b1c6 100644 --- a/strawberry/federation/field.py +++ b/strawberry/federation/field.py @@ -204,7 +204,7 @@ def field( # This init parameter is used by PyRight to determine whether this field # is added in the constructor or not. It is not used to change # any behavior at the moment. - init: Literal[True, False, None] = None, + init: Optional[Literal[True, False]] = None, ) -> Any: from .schema_directives import ( Authenticated, diff --git a/strawberry/flask/views.py b/strawberry/flask/views.py index 995069901a..3c8a45a067 100644 --- a/strawberry/flask/views.py +++ b/strawberry/flask/views.py @@ -19,6 +19,7 @@ if TYPE_CHECKING: from flask.typing import ResponseReturnValue + from strawberry.http import GraphQLHTTPResponse from strawberry.http.ides import GraphQL_IDE from strawberry.schema.base import BaseSchema diff --git a/strawberry/litestar/controller.py b/strawberry/litestar/controller.py index 3008d8ec4a..e02f351fd6 100644 --- a/strawberry/litestar/controller.py +++ b/strawberry/litestar/controller.py @@ -17,6 +17,15 @@ from typing_extensions import TypeGuard from lia import HTTPException, LitestarRequestAdapter +from litestar.background_tasks import BackgroundTasks +from litestar.di import Provide +from litestar.exceptions import ( + NotFoundException, + ValidationException, + WebSocketDisconnect, +) +from litestar.response.streaming import Stream +from litestar.status_codes import HTTP_200_OK from msgspec import Struct from litestar import ( @@ -29,15 +38,6 @@ post, websocket, ) -from litestar.background_tasks import BackgroundTasks -from litestar.di import Provide -from litestar.exceptions import ( - NotFoundException, - ValidationException, - WebSocketDisconnect, -) -from litestar.response.streaming import Stream -from litestar.status_codes import HTTP_200_OK from strawberry.exceptions import InvalidCustomContext from strawberry.http.async_base_view import ( AsyncBaseHTTPView, @@ -55,6 +55,7 @@ from collections.abc import AsyncGenerator, AsyncIterator, Mapping, Sequence from litestar.types import AnyCallable, Dependencies + from strawberry.http import GraphQLHTTPResponse from strawberry.http.ides import GraphQL_IDE from strawberry.schema import BaseSchema diff --git a/strawberry/quart/views.py b/strawberry/quart/views.py index e8df22ba33..0378bddc21 100644 --- a/strawberry/quart/views.py +++ b/strawberry/quart/views.py @@ -7,9 +7,9 @@ from typing_extensions import TypeGuard from lia import HTTPException, QuartHTTPRequestAdapter +from quart.ctx import has_websocket_context from quart import Request, Response, Websocket, request, websocket -from quart.ctx import has_websocket_context from quart.views import View from strawberry.http.async_base_view import ( AsyncBaseHTTPView, @@ -26,6 +26,7 @@ if TYPE_CHECKING: from quart.typing import ResponseReturnValue + from strawberry.http import GraphQLHTTPResponse from strawberry.schema.base import BaseSchema diff --git a/strawberry/relay/fields.py b/strawberry/relay/fields.py index b802a7287d..574aeb0c09 100644 --- a/strawberry/relay/fields.py +++ b/strawberry/relay/fields.py @@ -396,7 +396,7 @@ def connection( # This init parameter is used by pyright to determine whether this field # is added in the constructor or not. It is not used to change # any behaviour at the moment. - init: Literal[True, False, None] = None, + init: Optional[Literal[True, False]] = None, ) -> Any: """Annotate a property or a method to create a relay connection field. diff --git a/strawberry/sanic/context.py b/strawberry/sanic/context.py index d828282fe8..2a528c8451 100644 --- a/strawberry/sanic/context.py +++ b/strawberry/sanic/context.py @@ -2,6 +2,7 @@ from typing_extensions import TypedDict from sanic.request import Request + from strawberry.http.temporal_response import TemporalResponse diff --git a/strawberry/sanic/views.py b/strawberry/sanic/views.py index e9904f25bb..95e3110715 100644 --- a/strawberry/sanic/views.py +++ b/strawberry/sanic/views.py @@ -12,9 +12,9 @@ from typing_extensions import TypeGuard from lia import HTTPException, SanicHTTPRequestAdapter - from sanic.request import Request from sanic.response import HTTPResponse, html + from sanic.views import HTTPMethodView from strawberry.http.async_base_view import AsyncBaseHTTPView from strawberry.http.temporal_response import TemporalResponse diff --git a/strawberry/types/field.py b/strawberry/types/field.py index 0e06b7dd0a..6e2f4fa7d7 100644 --- a/strawberry/types/field.py +++ b/strawberry/types/field.py @@ -514,7 +514,7 @@ def field( # This init parameter is used by PyRight to determine whether this field # is added in the constructor or not. It is not used to change # any behavior at the moment. - init: Literal[True, False, None] = None, + init: Optional[Literal[True, False]] = None, ) -> Any: """Annotates a method or property as a GraphQL field. diff --git a/strawberry/types/mutation.py b/strawberry/types/mutation.py index 183240c213..a6a666ca15 100644 --- a/strawberry/types/mutation.py +++ b/strawberry/types/mutation.py @@ -134,7 +134,7 @@ def mutation( # This init parameter is used by PyRight to determine whether this field # is added in the constructor or not. It is not used to change # any behavior at the moment. - init: Literal[True, False, None] = None, + init: Optional[Literal[True, False]] = None, ) -> Any: """Annotates a method or property as a GraphQL mutation. @@ -291,7 +291,7 @@ def subscription( directives: Optional[Sequence[object]] = (), extensions: Optional[list[FieldExtension]] = None, graphql_type: Optional[Any] = None, - init: Literal[True, False, None] = None, + init: Optional[Literal[True, False]] = None, ) -> Any: """Annotates a method or property as a GraphQL subscription. diff --git a/tests/fastapi/test_context.py b/tests/fastapi/test_context.py index c5a9147289..0c74354e3a 100644 --- a/tests/fastapi/test_context.py +++ b/tests/fastapi/test_context.py @@ -22,8 +22,9 @@ def test_base_context(): def test_with_explicit_class_context_getter(): - from fastapi import Depends, FastAPI from fastapi.testclient import TestClient + + from fastapi import Depends, FastAPI from strawberry.fastapi import BaseContext, GraphQLRouter @strawberry.type @@ -58,8 +59,9 @@ def get_context(custom_context: CustomContext = Depends(custom_context_dependenc def test_with_implicit_class_context_getter(): - from fastapi import Depends, FastAPI from fastapi.testclient import TestClient + + from fastapi import Depends, FastAPI from strawberry.fastapi import BaseContext, GraphQLRouter @strawberry.type @@ -92,8 +94,9 @@ def get_context(custom_context: CustomContext = Depends()): def test_with_dict_context_getter(): - from fastapi import Depends, FastAPI from fastapi.testclient import TestClient + + from fastapi import Depends, FastAPI from strawberry.fastapi import GraphQLRouter @strawberry.type @@ -124,8 +127,9 @@ def get_context(value: str = Depends(custom_context_dependency)) -> dict[str, st def test_without_context_getter(): - from fastapi import FastAPI from fastapi.testclient import TestClient + + from fastapi import FastAPI from strawberry.fastapi import GraphQLRouter @strawberry.type @@ -149,8 +153,9 @@ def abc(self, info: strawberry.Info) -> str: def test_with_invalid_context_getter(): - from fastapi import Depends, FastAPI from fastapi.testclient import TestClient + + from fastapi import Depends, FastAPI from strawberry.fastapi import GraphQLRouter @strawberry.type @@ -184,8 +189,9 @@ def get_context(value: str = Depends(custom_context_dependency)) -> str: def test_class_context_injects_connection_params_over_transport_ws(): - from fastapi import Depends, FastAPI from fastapi.testclient import TestClient + + from fastapi import Depends, FastAPI from strawberry.fastapi import BaseContext, GraphQLRouter @strawberry.type @@ -256,10 +262,10 @@ def get_context(context: Context = Depends()) -> Context: def test_class_context_injects_connection_params_over_ws(): + from fastapi.testclient import TestClient from starlette.websockets import WebSocketDisconnect from fastapi import Depends, FastAPI - from fastapi.testclient import TestClient from strawberry.fastapi import BaseContext, GraphQLRouter @strawberry.type diff --git a/tests/http/clients/aiohttp.py b/tests/http/clients/aiohttp.py index 7e436100dc..071723a16e 100644 --- a/tests/http/clients/aiohttp.py +++ b/tests/http/clients/aiohttp.py @@ -8,10 +8,11 @@ from typing import Any, Optional, Union from typing_extensions import Literal -from aiohttp import web from aiohttp.client_ws import ClientWebSocketResponse from aiohttp.http_websocket import WSMsgType from aiohttp.test_utils import TestClient, TestServer + +from aiohttp import web from strawberry.aiohttp.views import GraphQLView as BaseGraphQLView from strawberry.http import GraphQLHTTPResponse from strawberry.http.ides import GraphQL_IDE diff --git a/tests/http/clients/chalice.py b/tests/http/clients/chalice.py index c70b170dc0..4a339b4ac4 100644 --- a/tests/http/clients/chalice.py +++ b/tests/http/clients/chalice.py @@ -9,6 +9,7 @@ from chalice.app import Chalice from chalice.app import Request as ChaliceRequest from chalice.test import Client + from strawberry import Schema from strawberry.chalice.views import GraphQLView as BaseGraphQLView from strawberry.http import GraphQLHTTPResponse diff --git a/tests/http/clients/fastapi.py b/tests/http/clients/fastapi.py index 7164a8176f..ba2f992d7e 100644 --- a/tests/http/clients/fastapi.py +++ b/tests/http/clients/fastapi.py @@ -8,8 +8,9 @@ from typing import Any, Optional from typing_extensions import Literal -from fastapi import BackgroundTasks, Depends, FastAPI, Request, WebSocket from fastapi.testclient import TestClient + +from fastapi import BackgroundTasks, Depends, FastAPI, Request, WebSocket from strawberry.fastapi import GraphQLRouter as BaseGraphQLRouter from strawberry.http import GraphQLHTTPResponse from strawberry.http.ides import GraphQL_IDE diff --git a/tests/http/clients/litestar.py b/tests/http/clients/litestar.py index 1491ed327f..0c3eccbae0 100644 --- a/tests/http/clients/litestar.py +++ b/tests/http/clients/litestar.py @@ -8,10 +8,11 @@ from typing import Any, Optional from typing_extensions import Literal -from litestar import Litestar, Request from litestar.exceptions import WebSocketDisconnect from litestar.testing import TestClient from litestar.testing.websocket_test_session import WebSocketTestSession + +from litestar import Litestar, Request from strawberry.http import GraphQLHTTPResponse from strawberry.http.ides import GraphQL_IDE from strawberry.litestar import make_graphql_controller diff --git a/tests/http/clients/quart.py b/tests/http/clients/quart.py index d797bcf896..9e74913ca8 100644 --- a/tests/http/clients/quart.py +++ b/tests/http/clients/quart.py @@ -7,6 +7,7 @@ from typing import Any, Optional, Union from typing_extensions import Literal +from quart.datastructures import FileStorage from starlette.testclient import TestClient from starlette.types import Receive, Scope, Send @@ -14,7 +15,6 @@ from quart import Request as QuartRequest from quart import Response as QuartResponse from quart import Websocket as QuartWebsocket -from quart.datastructures import FileStorage from strawberry.http import GraphQLHTTPResponse from strawberry.http.ides import GraphQL_IDE from strawberry.quart.views import GraphQLView as BaseGraphQLView diff --git a/tests/http/clients/sanic.py b/tests/http/clients/sanic.py index d2794d3c9f..c886d5931b 100644 --- a/tests/http/clients/sanic.py +++ b/tests/http/clients/sanic.py @@ -6,8 +6,9 @@ from typing import Any, Optional from typing_extensions import Literal -from sanic import Sanic from sanic.request import Request as SanicRequest + +from sanic import Sanic from strawberry.http import GraphQLHTTPResponse from strawberry.http.ides import GraphQL_IDE from strawberry.http.temporal_response import TemporalResponse diff --git a/tests/litestar/app.py b/tests/litestar/app.py index 3ed6945564..9e986979dd 100644 --- a/tests/litestar/app.py +++ b/tests/litestar/app.py @@ -1,7 +1,8 @@ from typing import Any -from litestar import Litestar, Request from litestar.di import Provide + +from litestar import Litestar, Request from strawberry.litestar import make_graphql_controller from tests.views.schema import schema diff --git a/tests/litestar/conftest.py b/tests/litestar/conftest.py index 45f196d62d..49dd8b5571 100644 --- a/tests/litestar/conftest.py +++ b/tests/litestar/conftest.py @@ -4,6 +4,7 @@ @pytest.fixture def test_client(): from litestar.testing import TestClient + from tests.litestar.app import create_app app = create_app() @@ -13,6 +14,7 @@ def test_client(): @pytest.fixture def test_client_keep_alive(): from litestar.testing import TestClient + from tests.litestar.app import create_app app = create_app(keep_alive=True, keep_alive_interval=0.1) diff --git a/tests/litestar/test_context.py b/tests/litestar/test_context.py index 2243eb61ee..337f72f6de 100644 --- a/tests/litestar/test_context.py +++ b/tests/litestar/test_context.py @@ -9,9 +9,10 @@ def test_base_context(): def test_with_class_context_getter(): - from litestar import Litestar from litestar.di import Provide from litestar.testing import TestClient + + from litestar import Litestar from strawberry.litestar import BaseContext, make_graphql_controller @strawberry.type @@ -53,9 +54,10 @@ async def get_context(custom_context_dependency: CustomContext): def test_with_dict_context_getter(): - from litestar import Litestar from litestar.di import Provide from litestar.testing import TestClient + + from litestar import Litestar from strawberry.litestar import make_graphql_controller @strawberry.type @@ -93,8 +95,9 @@ async def get_context(custom_context_dependency: str) -> dict[str, str]: def test_without_context_getter(): - from litestar import Litestar from litestar.testing import TestClient + + from litestar import Litestar from strawberry.litestar import make_graphql_controller @strawberry.type @@ -119,9 +122,10 @@ def abc(self, info: strawberry.Info) -> str: def test_with_invalid_context_getter(): - from litestar import Litestar from litestar.di import Provide from litestar.testing import TestClient + + from litestar import Litestar from strawberry.litestar import make_graphql_controller @strawberry.type @@ -165,6 +169,7 @@ async def get_context(custom_context_dependency: str) -> str: def test_custom_context(): from litestar.testing import TestClient + from tests.litestar.app import create_app @strawberry.type @@ -185,6 +190,7 @@ def custom_context_value(self, info: strawberry.Info) -> str: def test_can_set_background_task(): from litestar.testing import TestClient + from tests.litestar.app import create_app task_complete = False diff --git a/tests/litestar/test_response_headers.py b/tests/litestar/test_response_headers.py index 7a70045841..949b8d3507 100644 --- a/tests/litestar/test_response_headers.py +++ b/tests/litestar/test_response_headers.py @@ -3,8 +3,9 @@ # TODO: move this to common tests def test_set_response_headers(): - from litestar import Litestar from litestar.testing import TestClient + + from litestar import Litestar from strawberry.litestar import make_graphql_controller @strawberry.type @@ -29,8 +30,9 @@ def abc(self, info: strawberry.Info) -> str: def test_set_cookie_headers(): - from litestar import Litestar from litestar.testing import TestClient + + from litestar import Litestar from strawberry.litestar import make_graphql_controller @strawberry.type diff --git a/tests/litestar/test_response_status.py b/tests/litestar/test_response_status.py index 879ac9a30a..1564db32d8 100644 --- a/tests/litestar/test_response_status.py +++ b/tests/litestar/test_response_status.py @@ -3,8 +3,9 @@ # TODO: move this to common tests def test_set_custom_http_response_status(): - from litestar import Litestar from litestar.testing import TestClient + + from litestar import Litestar from strawberry.litestar import make_graphql_controller @strawberry.type @@ -26,8 +27,9 @@ def abc(self, info: strawberry.Info) -> str: def test_set_without_setting_http_response_status(): - from litestar import Litestar from litestar.testing import TestClient + + from litestar import Litestar from strawberry.litestar import make_graphql_controller @strawberry.type diff --git a/tests/sanic/test_file_upload.py b/tests/sanic/test_file_upload.py index 79c4fffff7..16edc06c8f 100644 --- a/tests/sanic/test_file_upload.py +++ b/tests/sanic/test_file_upload.py @@ -47,6 +47,7 @@ def app(): def test_file_cast(app: Sanic): """Tests that the list of files in a sanic Request gets correctly turned into a dictionary""" from sanic.request import File + from strawberry.sanic import utils file_name = "test.txt" diff --git a/tests/test/conftest.py b/tests/test/conftest.py index 0fa1001dd3..2ef7ef83ba 100644 --- a/tests/test/conftest.py +++ b/tests/test/conftest.py @@ -15,8 +15,9 @@ @asynccontextmanager async def aiohttp_graphql_client() -> AsyncGenerator[BaseGraphQLTestClient]: try: - from aiohttp import web from aiohttp.test_utils import TestClient, TestServer + + from aiohttp import web from strawberry.aiohttp.test import GraphQLTestClient from strawberry.aiohttp.views import GraphQLView except ImportError: