refactor: convert f-string logging to lazy %-style format (G004)
Sweep all 1676 G004 violations across 112 files, converting
`logger.<level>(f"…{x}…")` to `logger.<level>("…%s…", x)`.
Why: ruff rule G004 was added to pyproject.toml to enforce lazy
%-style logging — defers formatting until the log level is enabled
and lets structured log tooling match the unformatted template.
Conversion preserves rendered output byte-for-byte:
- `{x}` → `%s` + `x`
- `{x!r}` / `{x!s}` / `{x!a}` → `%r` / `%s` / `%a`
- Format specs (`{x:.2f}`, `{x:>10}`) → `%s` + `format(x, 'spec')`
(printf-style specs aren't 1:1 with Python format specs, so we
delegate to `format()` to keep identical output)
- Literal `%` → `%%`
- Concatenated f-strings (`f"a {x} " "b"`) flattened
- Trailing kwargs (`exc_info=True`) preserved
Verified:
- `uv run ruff check --select G004` → 0 violations
- `uv run ty check -- nextcloud_mcp_server` → passes
- `uv run pytest tests/unit/` → 1010 passed
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
a4e6125d28
commit
665cb9b1eb
@@ -359,7 +359,8 @@ async def oauth_authorize(request: Request) -> RedirectResponse | JSONResponse:
|
||||
if auth_parsed.query:
|
||||
authorization_endpoint += f"?{auth_parsed.query}"
|
||||
logger.info(
|
||||
f"Rewrote authorization endpoint for browser access: {authorization_endpoint}"
|
||||
"Rewrote authorization endpoint for browser access: %s",
|
||||
authorization_endpoint,
|
||||
)
|
||||
|
||||
# Prefix resource scopes with the resource server identifier if configured.
|
||||
@@ -952,7 +953,7 @@ async def _oauth_callback_as_proxy(
|
||||
|
||||
if response.status_code != 200:
|
||||
logger.error(
|
||||
f"AS proxy token exchange failed: {response.status_code} {response.text}"
|
||||
"AS proxy token exchange failed: %s %s", response.status_code, response.text
|
||||
)
|
||||
params = urlencode(
|
||||
{
|
||||
@@ -968,8 +969,8 @@ async def _oauth_callback_as_proxy(
|
||||
nc_token_response = response.json()
|
||||
|
||||
logger.info(
|
||||
"AS proxy: Successfully exchanged code for Nextcloud token "
|
||||
f"(token_type={nc_token_response.get('token_type')})"
|
||||
"AS proxy: Successfully exchanged code for Nextcloud token (token_type=%s)",
|
||||
nc_token_response.get("token_type"),
|
||||
)
|
||||
|
||||
# Verify the ID token signature + claims before caching the response
|
||||
@@ -1017,7 +1018,8 @@ async def _oauth_callback_as_proxy(
|
||||
redirect_url = f"{session.client_redirect_uri}?{redirect_params}"
|
||||
|
||||
logger.info(
|
||||
f"AS proxy: Redirecting to client with proxy_code (client_id={session.client_id})"
|
||||
"AS proxy: Redirecting to client with proxy_code (client_id=%s)",
|
||||
session.client_id,
|
||||
)
|
||||
return RedirectResponse(redirect_url, status_code=302)
|
||||
|
||||
@@ -1294,7 +1296,7 @@ async def _token_refresh(request: Request, form) -> JSONResponse:
|
||||
|
||||
if response.status_code != 200:
|
||||
logger.error(
|
||||
f"AS proxy token refresh failed: {response.status_code} {response.text}"
|
||||
"AS proxy token refresh failed: %s %s", response.status_code, response.text
|
||||
)
|
||||
return JSONResponse(
|
||||
{
|
||||
@@ -1396,7 +1398,9 @@ async def oauth_register_proxy(request: Request) -> JSONResponse:
|
||||
|
||||
if response.status_code not in (200, 201):
|
||||
logger.error(
|
||||
f"DCR proxy: Upstream registration failed: {response.status_code} {response.text}"
|
||||
"DCR proxy: Upstream registration failed: %s %s",
|
||||
response.status_code,
|
||||
response.text,
|
||||
)
|
||||
return JSONResponse(
|
||||
response.json()
|
||||
|
||||
Reference in New Issue
Block a user