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
@@ -43,7 +43,8 @@ def retry_on_429(func):
|
||||
# error we wait a couple of seconds and do a retry
|
||||
if e.response.status_code == codes.TOO_MANY_REQUESTS:
|
||||
logger.warning(
|
||||
f"429 Client Error: Too Many Requests, Number of attempts: {retries}"
|
||||
"429 Client Error: Too Many Requests, Number of attempts: %s",
|
||||
retries,
|
||||
)
|
||||
# Record retry metric (extract app name from args if available)
|
||||
if len(args) > 0 and hasattr(args[0], "app_name"):
|
||||
@@ -53,17 +54,26 @@ def retry_on_429(func):
|
||||
# 404 errors are often expected (e.g., checking if attachments exist)
|
||||
# Log as debug instead of warning
|
||||
logger.debug(
|
||||
f"HTTPStatusError {e.response.status_code}: {e}, Number of attempts: {retries}"
|
||||
"HTTPStatusError %s: %s, Number of attempts: %s",
|
||||
e.response.status_code,
|
||||
e,
|
||||
retries,
|
||||
)
|
||||
raise
|
||||
else:
|
||||
logger.warning(
|
||||
f"HTTPStatusError {e.response.status_code}: {e}, Number of attempts: {retries}"
|
||||
"HTTPStatusError %s: %s, Number of attempts: %s",
|
||||
e.response.status_code,
|
||||
e,
|
||||
retries,
|
||||
)
|
||||
raise
|
||||
except RequestError as e:
|
||||
logger.warning(
|
||||
f"RequestError {e.request.url}: {e}, Number of attempts: {retries}"
|
||||
"RequestError %s: %s, Number of attempts: %s",
|
||||
e.request.url,
|
||||
e,
|
||||
retries,
|
||||
)
|
||||
raise
|
||||
|
||||
@@ -127,7 +137,7 @@ class BaseNextcloudClient(ABC):
|
||||
Response object
|
||||
"""
|
||||
url = self._resolve_url(url)
|
||||
logger.debug(f"Making {method} request to {url}")
|
||||
logger.debug("Making %s request to %s", method, url)
|
||||
|
||||
# Start timer for metrics
|
||||
start_time = time.time()
|
||||
|
||||
Reference in New Issue
Block a user