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
@@ -129,7 +129,7 @@ class LoginFlowV2Client:
|
||||
f"Malformed Login Flow v2 initiate response from Nextcloud (missing key: {e})"
|
||||
) from e
|
||||
|
||||
logger.info(f"Login Flow v2 initiated: login_url={result.login_url[:60]}...")
|
||||
logger.info("Login Flow v2 initiated: login_url=%s...", result.login_url[:60])
|
||||
return result
|
||||
|
||||
def _rewrite_to_nextcloud_host(self, url: str) -> str:
|
||||
@@ -142,7 +142,7 @@ class LoginFlowV2Client:
|
||||
"""
|
||||
result = rewrite_url_origin(url, self.nextcloud_host)
|
||||
if result != url:
|
||||
logger.debug(f"Rewrote Login Flow v2 URL: {url} → {result}")
|
||||
logger.debug("Rewrote Login Flow v2 URL: %s → %s", url, result)
|
||||
return result
|
||||
|
||||
async def poll(self, poll_endpoint: str, poll_token: str) -> LoginFlowPollResult:
|
||||
@@ -172,8 +172,9 @@ class LoginFlowV2Client:
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
logger.info(
|
||||
f"Login Flow v2 completed: server={data.get('server')}, "
|
||||
f"loginName={data.get('loginName')}"
|
||||
"Login Flow v2 completed: server=%s, loginName=%s",
|
||||
data.get("server"),
|
||||
data.get("loginName"),
|
||||
)
|
||||
try:
|
||||
return LoginFlowPollResult(
|
||||
@@ -193,6 +194,6 @@ class LoginFlowV2Client:
|
||||
|
||||
# Any other status indicates the flow has expired or is invalid
|
||||
logger.warning(
|
||||
f"Login Flow v2 poll returned unexpected status: {response.status_code}"
|
||||
"Login Flow v2 poll returned unexpected status: %s", response.status_code
|
||||
)
|
||||
return LoginFlowPollResult(status="expired")
|
||||
|
||||
Reference in New Issue
Block a user