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
+14 -12
View File
@@ -89,7 +89,7 @@ class ClientRegistry:
if not cid or not redirect:
logger.warning(
f"Skipping malformed ALLOWED_MCP_CLIENTS entry: {entry!r}"
"Skipping malformed ALLOWED_MCP_CLIENTS entry: %r", entry
)
continue
@@ -97,8 +97,9 @@ class ClientRegistry:
hostname = parsed.hostname
if hostname is None:
logger.warning(
f"Skipping client {cid!r}: cannot parse hostname "
f"from {redirect!r}"
"Skipping client %r: cannot parse hostname from %r",
cid,
redirect,
)
continue
is_loopback = hostname in ("localhost", "127.0.0.1", "::1")
@@ -108,8 +109,9 @@ class ClientRegistry:
or (parsed.scheme == "http" and is_loopback)
):
logger.warning(
f"Rejecting client {cid!r}: HTTP redirect URIs are only "
f"allowed for localhost, got {redirect!r}"
"Rejecting client %r: HTTP redirect URIs are only allowed for localhost, got %r",
cid,
redirect,
)
continue
@@ -120,7 +122,7 @@ class ClientRegistry:
allowed_scopes=["*"],
is_public=True,
)
logger.info(f"Registered static client: {cid}")
logger.info("Registered static client: %s", cid)
else:
self._clients[entry] = MCPClientInfo(
client_id=entry,
@@ -129,7 +131,7 @@ class ClientRegistry:
allowed_scopes=["*"],
is_public=True,
)
logger.info(f"Registered static client: {entry}")
logger.info("Registered static client: %s", entry)
if not self._clients:
logger.warning(
@@ -170,7 +172,7 @@ class ClientRegistry:
if not client:
if self.allow_dynamic_registration:
# In production, would attempt DCR here
logger.info(f"Unknown client {client_id}, would attempt DCR")
logger.info("Unknown client %s, would attempt DCR", client_id)
return True, None
else:
return False, f"Unknown client_id: {client_id}"
@@ -229,15 +231,15 @@ class ClientRegistry:
True if registered successfully
"""
if not self.allow_dynamic_registration:
logger.warning(f"DCR disabled, cannot register {client_info.client_id}")
logger.warning("DCR disabled, cannot register %s", client_info.client_id)
return False
if client_info.client_id in self._clients:
logger.warning(f"Client {client_info.client_id} already registered")
logger.warning("Client %s already registered", client_info.client_id)
return False
self._clients[client_info.client_id] = client_info
logger.info(f"Dynamically registered client: {client_info.client_id}")
logger.info("Dynamically registered client: %s", client_info.client_id)
# In production, would persist to database
return True
@@ -263,7 +265,7 @@ class ClientRegistry:
allowed_scopes=["*"], # Nextcloud enforces actual scopes
is_public=True,
)
logger.info(f"Registered proxy client: {client_id}")
logger.info("Registered proxy client: %s", client_id)
def get_client(self, client_id: str) -> Optional[MCPClientInfo]:
"""