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:
Chris Coutinho
2026-05-13 01:12:17 +02:00
co-authored by Claude Opus 4.7
parent a4e6125d28
commit 665cb9b1eb
112 changed files with 2534 additions and 1859 deletions
+8 -7
View File
@@ -143,7 +143,7 @@ def _extract_basic_auth(
# Verify username matches path user_id
if username != path_user_id:
logger.warning(
f"Username mismatch in app password operation for path user {path_user_id}"
"Username mismatch in app password operation for path user %s", path_user_id
)
return (
"",
@@ -211,7 +211,7 @@ async def provision_app_password(request: Request) -> JSONResponse:
is_allowed, retry_after = _check_rate_limit(path_user_id)
if not is_allowed:
logger.warning(
f"Rate limit exceeded for app password provisioning: {path_user_id}"
"Rate limit exceeded for app password provisioning: %s", path_user_id
)
return JSONResponse(
{
@@ -263,7 +263,8 @@ async def provision_app_password(request: Request) -> JSONResponse:
if response.status_code != 200:
logger.warning(
f"App password validation failed for user: HTTP {response.status_code}"
"App password validation failed for user: HTTP %s",
response.status_code,
)
_record_rate_limit_attempt(path_user_id, success=False)
return JSONResponse(
@@ -283,7 +284,7 @@ async def provision_app_password(request: Request) -> JSONResponse:
)
except httpx.RequestError as e:
logger.error(f"Failed to validate app password: {e}")
logger.error("Failed to validate app password: %s", e)
return JSONResponse(
{"success": False, "error": "Failed to validate credentials"},
status_code=500,
@@ -309,7 +310,7 @@ async def provision_app_password(request: Request) -> JSONResponse:
invalidate_scope_cache(username)
_record_rate_limit_attempt(path_user_id, success=True)
logger.info(f"Provisioned app password for user: {username}")
logger.info("Provisioned app password for user: %s", username)
return JSONResponse(
{
@@ -409,7 +410,7 @@ async def delete_app_password(request: Request) -> JSONResponse:
status_code=401,
)
except httpx.RequestError as e:
logger.error(f"Failed to validate credentials: {e}")
logger.error("Failed to validate credentials: %s", e)
return JSONResponse(
{"success": False, "error": "Failed to validate credentials"},
status_code=500,
@@ -420,7 +421,7 @@ async def delete_app_password(request: Request) -> JSONResponse:
deleted = await storage.delete_app_password(username)
if deleted:
logger.info(f"Deleted app password for user: {username}")
logger.info("Deleted app password for user: %s", username)
return JSONResponse(
{
"success": True,