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
@@ -122,13 +122,19 @@ async def write_placeholder_point(
|
||||
)
|
||||
|
||||
logger.debug(
|
||||
f"Wrote placeholder for {doc_type}_{doc_id} (user={user_id}, "
|
||||
f"modified_at={modified_at})"
|
||||
"Wrote placeholder for %s_%s (user=%s, modified_at=%s)",
|
||||
doc_type,
|
||||
doc_id,
|
||||
user_id,
|
||||
modified_at,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Failed to write placeholder for {doc_type}_{doc_id}: {e}",
|
||||
"Failed to write placeholder for %s_%s: %s",
|
||||
doc_type,
|
||||
doc_id,
|
||||
e,
|
||||
exc_info=True,
|
||||
)
|
||||
raise
|
||||
@@ -180,7 +186,9 @@ async def query_document_metadata(
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Error querying document metadata for {doc_type}_{doc_id}: {e}")
|
||||
logger.warning(
|
||||
"Error querying document metadata for %s_%s: %s", doc_type, doc_id, e
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
@@ -219,11 +227,16 @@ async def delete_placeholder_point(
|
||||
),
|
||||
)
|
||||
|
||||
logger.debug(f"Deleted placeholder for {doc_type}_{doc_id} (user={user_id})")
|
||||
logger.debug(
|
||||
"Deleted placeholder for %s_%s (user=%s)", doc_type, doc_id, user_id
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Failed to delete placeholder for {doc_type}_{doc_id}: {e}",
|
||||
"Failed to delete placeholder for %s_%s: %s",
|
||||
doc_type,
|
||||
doc_id,
|
||||
e,
|
||||
exc_info=True,
|
||||
)
|
||||
raise
|
||||
@@ -271,13 +284,16 @@ async def update_placeholder_status(
|
||||
)
|
||||
|
||||
logger.debug(
|
||||
f"Updated placeholder status for {doc_type}_{doc_id} to '{status}' "
|
||||
f"(user={user_id})"
|
||||
"Updated placeholder status for %s_%s to '%s' (user=%s)",
|
||||
doc_type,
|
||||
doc_id,
|
||||
status,
|
||||
user_id,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Failed to update placeholder status for {doc_type}_{doc_id}: {e}"
|
||||
"Failed to update placeholder status for %s_%s: %s", doc_type, doc_id, e
|
||||
)
|
||||
# Don't raise - status updates are non-critical
|
||||
|
||||
|
||||
Reference in New Issue
Block a user