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
+5 -5
View File
@@ -89,7 +89,7 @@ class ContactsClient(BaseNextcloudClient):
}
)
logger.debug(f"Found {len(addressbooks)} addressbooks")
logger.debug("Found %s addressbooks", len(addressbooks))
return addressbooks
async def create_addressbook(self, *, name: str, display_name: str):
@@ -166,7 +166,7 @@ class ContactsClient(BaseNextcloudClient):
except Exception:
# Fall back to creating new vCard if we can't get existing
logger.warning(
f"Could not fetch existing vCard for {uid}, creating new"
"Could not fetch existing vCard for %s, creating new", uid
)
raw_vcard_content = ""
@@ -283,7 +283,7 @@ class ContactsClient(BaseNextcloudClient):
}
)
logger.debug(f"Found {len(contacts)} contacts")
logger.debug("Found %s contacts", len(contacts))
return contacts
async def _get_raw_vcard(self, addressbook: str, uid: str) -> tuple[str, str]:
@@ -296,7 +296,7 @@ class ContactsClient(BaseNextcloudClient):
etag = response.headers.get("etag", "")
return response.text, etag
except Exception as e:
logger.error(f"Error getting raw vCard for {uid}: {e}")
logger.error("Error getting raw vCard for %s: %s", uid, e)
raise
def _merge_vcard_properties(
@@ -428,7 +428,7 @@ class ContactsClient(BaseNextcloudClient):
return "\n".join(updated_lines)
except Exception as e:
logger.error(f"Error merging vCard properties: {e}")
logger.error("Error merging vCard properties: %s", e)
# Fallback to creating basic vCard matching Nextcloud format
basic_vcard = f"""BEGIN:VCARD
VERSION:3.0