From 29bf20d00eef7986eef0b12b5a3822a7e27393fc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 23 Sep 2025 09:10:39 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20format?= =?UTF-8?q?=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/routing.py | 3 ++- tests/test_get_query_param.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fastapi/routing.py b/fastapi/routing.py index 7d5059ba9..3a0720de1 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -4444,7 +4444,8 @@ class APIRouter(routing.Router): return func return decorator - + + def get_query_param(request, name: str, default: str | None = None) -> str | None: """ Utility function to safely fetch a query parameter from a request. diff --git a/tests/test_get_query_param.py b/tests/test_get_query_param.py index b6287227d..ea02207b8 100644 --- a/tests/test_get_query_param.py +++ b/tests/test_get_query_param.py @@ -1,16 +1,17 @@ -import pytest -from starlette.requests import Request +from fastapi import FastAPI from fastapi.routing import get_query_param +from starlette.requests import Request from starlette.testclient import TestClient -from fastapi import FastAPI app = FastAPI() + @app.get("/demo") async def demo(request: Request): value = get_query_param(request, "name", default="guest") return {"name": value} + client = TestClient(app)