From 726a343bc4bd3e42e2424e7dd61cd6735ebfec7d Mon Sep 17 00:00:00 2001 From: IdoPort Date: Sun, 23 Aug 2026 13:27:46 +0300 Subject: [PATCH] fix(proxy): satisfy the type-discipline gate for the route-reordering fix - routes/new_route: Final, closing the LIT010 rebind-openness gap - # mutable-ok / # rebind-ok on the app.router.routes reassignment: it necessarily constructs a list literal and mutates state reachable from the app parameter, since Starlette's own Router.routes must stay a real, appendable list for the framework's own route registration to keep working -- an immutable rewrite is not possible here, per CLAUDE.md's own last-resort carve-out for this case CI failure: LIT002 total exceeded budget by the 1 new violation this PR added (https://github.com/BerriAI/litellm/pull/38017/checks). --- .../pass_through_endpoints/pass_through_endpoints.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py index dccc67ce47d..b1fd6492286 100644 --- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py @@ -2586,12 +2586,16 @@ class SafeRouteAdder: Builds the reordered list in one expression and reassigns app.router.routes wholesale, rather than mutating the existing list in place with pop()/insert(). """ - routes = app.routes - new_route = routes[-1] + routes: Final = app.routes + new_route: Final = routes[-1] for index, route in enumerate(routes[:-1]): route_path = getattr(route, "path", None) if route_path and SafeRouteAdder._GENERIC_PROVIDER_PATH_MARKER in route_path: - app.router.routes = [*routes[:index], new_route, *routes[index:-1]] + app.router.routes = [ # mutable-ok: framework's list # rebind-ok: reordering is the fix + *routes[:index], + new_route, + *routes[index:-1], + ] return @staticmethod