From 191fff3114bd099a088da5b22cd21a6252247619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 1 Jul 2026 18:04:20 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20dead=20code,=20adjust?= =?UTF-8?q?=20coverage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/routing.py | 7 ------- tests/test_frontend.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/fastapi/routing.py b/fastapi/routing.py index b6f2407e3..c442b122b 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -1511,8 +1511,6 @@ class _EffectiveRouteContext: return Match.FULL, child_scope def url_path_for(self, name: str, /, **path_params: Any) -> Any: - if isinstance(self.original_route, _FrontendRouteGroup): - raise routing.NoMatchFound(name, path_params) if not isinstance(self.original_route, APIRoute): assert self.starlette_route is not None return self.starlette_route.url_path_for(name, **path_params) @@ -2025,11 +2023,6 @@ class _FrontendRoute(BaseRoute): directory=directory, fallback=fallback, check_dir=check_dir ) - def with_path(self, path: str) -> "_FrontendRoute": - route = copy.copy(self) - route.path = _normalize_frontend_path(path) - return route - def matches(self, scope: Scope) -> tuple[Match, Scope]: return self.matches_with_path(scope, self.path) diff --git a/tests/test_frontend.py b/tests/test_frontend.py index bdad87700..b8dd62fb8 100644 --- a/tests/test_frontend.py +++ b/tests/test_frontend.py @@ -132,6 +132,12 @@ def test_frontend_route_group_helpers(tmp_path: Path): assert match == Match.FULL assert child_scope["fastapi"]["frontend_path"] == "" + match, child_scope = route_group.routes[0].matches( + {"type": "http", "path": "/app", "method": "GET"} + ) + assert match == Match.FULL + assert child_scope["fastapi"]["frontend_path"] == "" + with pytest.raises(StarletteHTTPException) as exc_info: anyio.run( route_group.handle, @@ -343,8 +349,18 @@ def test_included_frontend_does_not_block_url_path_for(tmp_path: Path): app = FastAPI() app.include_router(frontend_router, prefix="/app") app.include_router(api_router) + included_frontend = next( + route + for route in app.router.routes + if hasattr(route, "effective_low_priority_routes") + ) + with pytest.raises(NoMatchFound): + included_frontend.url_path_for("missing") assert app.url_path_for("read_api") == "/api" + response = TestClient(app).get("/api") + assert response.status_code == 200 + assert response.json() == {"ok": True} def test_include_router_frontend_dependencies_apply_in_nested_order(tmp_path: Path):