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
@@ -137,7 +137,7 @@ def _sanitize_error_for_client(error: Exception, context: str = "") -> str:
|
||||
Generic error message safe for client consumption
|
||||
"""
|
||||
# Log detailed error for debugging
|
||||
logger.error(f"Error in {context}: {error}", exc_info=True)
|
||||
logger.error("Error in %s: %s", context, error, exc_info=True)
|
||||
|
||||
# Return generic message
|
||||
return "An internal error occurred. Please contact your administrator."
|
||||
@@ -307,7 +307,7 @@ async def get_vector_sync_status(request: Request) -> JSONResponse:
|
||||
indexed_count = count_result.count
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to query Qdrant for indexed count: {e}")
|
||||
logger.warning("Failed to query Qdrant for indexed count: %s", e)
|
||||
# Continue with indexed_count = 0
|
||||
|
||||
# Determine status
|
||||
@@ -355,7 +355,7 @@ async def get_user_session(request: Request) -> JSONResponse:
|
||||
# Verify token user matches requested user
|
||||
if token_user_id != path_user_id:
|
||||
logger.warning(
|
||||
f"User {token_user_id} attempted to access session for {path_user_id}"
|
||||
"User %s attempted to access session for %s", token_user_id, path_user_id
|
||||
)
|
||||
return JSONResponse(
|
||||
{
|
||||
@@ -442,7 +442,7 @@ async def revoke_user_access(request: Request) -> JSONResponse:
|
||||
# Validate OAuth token and extract user
|
||||
token_user_id, validated = await validate_token_and_get_user(request)
|
||||
except Exception as e:
|
||||
logger.warning(f"Unauthorized access to /api/v1/users/{{user_id}}/revoke: {e}")
|
||||
logger.warning("Unauthorized access to /api/v1/users/{{user_id}}/revoke: %s", e)
|
||||
return JSONResponse(
|
||||
{
|
||||
"error": "Unauthorized",
|
||||
@@ -457,7 +457,7 @@ async def revoke_user_access(request: Request) -> JSONResponse:
|
||||
# Verify token user matches requested user
|
||||
if token_user_id != path_user_id:
|
||||
logger.warning(
|
||||
f"User {token_user_id} attempted to revoke access for {path_user_id}"
|
||||
"User %s attempted to revoke access for %s", token_user_id, path_user_id
|
||||
)
|
||||
return JSONResponse(
|
||||
{
|
||||
@@ -492,7 +492,8 @@ async def revoke_user_access(request: Request) -> JSONResponse:
|
||||
await token_broker.cache.invalidate(token_user_id)
|
||||
|
||||
logger.info(
|
||||
f"Revoked background access for user {token_user_id} (cache and storage cleared)"
|
||||
"Revoked background access for user %s (cache and storage cleared)",
|
||||
token_user_id,
|
||||
)
|
||||
|
||||
return JSONResponse(
|
||||
|
||||
Reference in New Issue
Block a user