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
@@ -62,7 +62,7 @@ def create_sampling_callback(provider: Provider):
|
||||
params: types.CreateMessageRequestParams,
|
||||
) -> types.CreateMessageResult | types.ErrorData:
|
||||
"""Handle sampling requests using the configured provider."""
|
||||
logger.debug(f"Sampling callback invoked with {len(params.messages)} messages")
|
||||
logger.debug("Sampling callback invoked with %s messages", len(params.messages))
|
||||
|
||||
# Extract messages and build prompt
|
||||
messages_text = []
|
||||
@@ -77,7 +77,7 @@ def create_sampling_callback(provider: Provider):
|
||||
if params.systemPrompt:
|
||||
prompt = f"System: {params.systemPrompt}\n\n{prompt}"
|
||||
|
||||
logger.debug(f"Generating response for prompt ({len(prompt)} chars)")
|
||||
logger.debug("Generating response for prompt (%s chars)", len(prompt))
|
||||
|
||||
try:
|
||||
# Generate response using provider
|
||||
@@ -87,7 +87,9 @@ def create_sampling_callback(provider: Provider):
|
||||
max_tokens=params.maxTokens,
|
||||
)
|
||||
|
||||
logger.info(f"Sampling completed: {len(response)} chars from {model_name}")
|
||||
logger.info(
|
||||
"Sampling completed: %s chars from %s", len(response), model_name
|
||||
)
|
||||
|
||||
return types.CreateMessageResult(
|
||||
role="assistant",
|
||||
@@ -96,7 +98,7 @@ def create_sampling_callback(provider: Provider):
|
||||
stopReason="endTurn",
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Generation failed ({provider.__class__.__name__}): {e}")
|
||||
logger.error("Generation failed (%s): %s", provider.__class__.__name__, e)
|
||||
return types.ErrorData(
|
||||
code=types.INTERNAL_ERROR,
|
||||
message=f"Generation failed: {e!s}",
|
||||
|
||||
Reference in New Issue
Block a user