From 89af929219c7db1d5987ca319b1ffc231d01b641 Mon Sep 17 00:00:00 2001 From: Johnny Huynh <27847622+johnnyhuy@users.noreply.github.com> Date: Sat, 19 Sep 2026 18:42:09 +1000 Subject: [PATCH] style: ruff format (#40) Post-merge format cleanup. CI's pinned ruff version enforces a tighter format than the local install; collapse 4 long-form expressions into single lines and unwrap multi-line dict literals. Co-authored-by: Claude --- opengateway/mojo_bridge/chat.py | 8 ++------ opengateway/mojo_bridge/routing.py | 15 ++++++--------- opengateway/mojo_bridge/stream.py | 4 +--- tests/test_cost_cap.py | 12 +++--------- 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/opengateway/mojo_bridge/chat.py b/opengateway/mojo_bridge/chat.py index c2dcf14..10717a2 100644 --- a/opengateway/mojo_bridge/chat.py +++ b/opengateway/mojo_bridge/chat.py @@ -56,9 +56,7 @@ def chat_completion( _enforce_rate_limit(auth) fallback_module = ( - _module_name_for(route.fallback) - if route is not None and route.fallback - else None + _module_name_for(route.fallback) if route is not None and route.fallback else None ) result, used_module = _run_with_fallback( body, @@ -89,9 +87,7 @@ def _run_with_fallback( import asyncio return asyncio.run( - chat_with_fallback( - body, primary_module=primary_module, fallback_module=fallback_module - ) + chat_with_fallback(body, primary_module=primary_module, fallback_module=fallback_module) ) diff --git a/opengateway/mojo_bridge/routing.py b/opengateway/mojo_bridge/routing.py index d547eab..9a75a97 100644 --- a/opengateway/mojo_bridge/routing.py +++ b/opengateway/mojo_bridge/routing.py @@ -199,9 +199,7 @@ def __init__(self, original: BaseException) -> None: self.original = original -def _provider_call_kwargs( - provider_module: str, body: dict[str, Any] -) -> tuple[str, str | None]: +def _provider_call_kwargs(provider_module: str, body: dict[str, Any]) -> tuple[str, str | None]: """Resolve the API key + base URL for ``provider_module``. Only enforces "API key configured" for modules with a registered @@ -215,9 +213,7 @@ def _provider_call_kwargs( return api_key or "", resolve_provider_base_url(provider_module) -async def _provider_chat( - provider_module: str, body: dict[str, Any] -) -> _OpenAIEnvelope: +async def _provider_chat(provider_module: str, body: dict[str, Any]) -> _OpenAIEnvelope: """Run a single non-streaming provider call, mapping transient failures to ``_RetryableError`` so ``chat_with_fallback`` can pick them up, and mapping non-retryable upstream HTTP errors to a plain @@ -245,8 +241,7 @@ async def _provider_chat( # internal_error, since this is the provider failing, not # us. raise RuntimeError( - f"upstream provider {provider_module} returned " - f"{exc.response.status_code}" + f"upstream provider {provider_module} returned {exc.response.status_code}" ) from exc raise finally: @@ -359,7 +354,9 @@ async def chat_stream_with_fallback( # ── Fallback attempt ─────────────────────────────────────────────── if fallback_module is None or fallback_module == primary_module or primary_failed is None: - raise StreamFallbackError(primary_failed or RuntimeError("primary failed"), on_fallback=False) + raise StreamFallbackError( + primary_failed or RuntimeError("primary failed"), on_fallback=False + ) logger.info( "retried streaming on fallback", diff --git a/opengateway/mojo_bridge/stream.py b/opengateway/mojo_bridge/stream.py index 1ae8c00..42824a2 100644 --- a/opengateway/mojo_bridge/stream.py +++ b/opengateway/mojo_bridge/stream.py @@ -243,9 +243,7 @@ def start_streaming_chat( raise RuntimeError(f"no API key configured for provider {resolved_primary}") fallback_module = ( - _routing_module_name(route.fallback) - if route is not None and route.fallback - else None + _routing_module_name(route.fallback) if route is not None and route.fallback else None ) if ( fallback_module is not None diff --git a/tests/test_cost_cap.py b/tests/test_cost_cap.py index ee63599..b9ea679 100644 --- a/tests/test_cost_cap.py +++ b/tests/test_cost_cap.py @@ -85,9 +85,7 @@ def test_cost_cap_rejects_when_estimate_exceeds_limit( _set_routes(monkeypatch) monkeypatch.setenv("ROOT_KEY", "sk-root-good") monkeypatch.setenv("OPENAI_API_KEY", "sk-test") - store = _FakeStore( - {_hash_key("sk-og-tenant"): _fake_record(max_cost_usd=0.01)} - ) + store = _FakeStore({_hash_key("sk-og-tenant"): _fake_record(max_cost_usd=0.01)}) monkeypatch.setattr("opengateway.mojo_bridge.db.get_store", lambda: store) envelope = handle_chat( @@ -165,9 +163,7 @@ def test_cost_cap_skipped_when_no_route_configured( monkeypatch.setenv("ROOT_KEY", "sk-root-good") monkeypatch.setenv("OPENAI_API_KEY", "sk-test") monkeypatch.delenv("ROUTES_JSON", raising=False) - store = _FakeStore( - {_hash_key("sk-og-tenant"): _fake_record(max_cost_usd=0.0001)} - ) + store = _FakeStore({_hash_key("sk-og-tenant"): _fake_record(max_cost_usd=0.0001)}) monkeypatch.setattr("opengateway.mojo_bridge.db.get_store", lambda: store) envelope = handle_chat( @@ -214,9 +210,7 @@ def test_cost_cap_enforced_on_streaming_too( _set_routes(monkeypatch) monkeypatch.setenv("ROOT_KEY", "sk-root-good") monkeypatch.setenv("OPENAI_API_KEY", "sk-test") - store = _FakeStore( - {_hash_key("sk-og-tenant"): _fake_record(max_cost_usd=0.01)} - ) + store = _FakeStore({_hash_key("sk-og-tenant"): _fake_record(max_cost_usd=0.01)}) monkeypatch.setattr("opengateway.mojo_bridge.db.get_store", lambda: store) envelope = handle_chat_stream(