Replace f-string usage in _LOGGER calls with printf style - #2272
Conversation
I didn't include your last commit (57b1f61) But I managed to get the rest of the diff change into an LLM. Not looked into it too much yet, but this is the output: Review summaryThe diff is mostly a safe conversion from f-strings to lazy logger formatting, but it introduces two definite logging errors and a few behavioural changes that should be reviewed before merging. Definite errors1. Incorrect logger arguments in
|
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
To account for new Ruff G004 rule.
Couple of missing %s were missed when switching, and a set of {} were not removed.
ab81188 to
5109946
Compare
|
Cool. I'm actually quite surprised how few mistakes there were in that change! As for the default functions (points 4 and 5), they weren't supposed to be in this PR, I must have based it on a working branch rather than main. |
Lost the return None in energy dashboard.
Fix CI lint check in plugin_solax.py
Upstream enabled ruff G004 (no f-strings in logging) in pyproject.toml and converted its own logging in PR wills106#2272, merged the day before this sync. Only one of our log calls trips it - the Full-write fallback error, which passed the f-string directly. The rest build their message into a variable first, because _remote_power_warn dedupes on the message text, so lazy formatting does not apply there. Also drops a stray blank line in NUMBER_TYPES that ruff format wanted; it came in with d3dd73d and predates the sync, so the tree is now format-clean too. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The problem with using f-strings in
_LOGGERcalls is that even if logging for that message level is disabled, formatting of the strings will still be performed.For infrequent logs that's a non-issue, but for e.g. auto-repeat loops or sensor calculations where this is happening every couple of seconds with multiple logs, it is potentially a lot of wasted processing time.
Using the printf style means the formatting will not be performed if debug logging is disabled.
This PR enables Ruff rule
G004which demands no f-strings in_LOGGERcalls, and replaces all such usages with standard printf style strings.Fixes #2023
Review Note:
While I've tried to take a lot of care in doing this, and checked as I went along, this was a manual process so its entirely possible that I've broken something in the process. We should check this PR thoroughly before merging it to try and catch any mistakes.
To aid this, I've tried to split up the commit history into a plugin by plugin basis to try and break it down into bitesize chunks.
Might be worth getting a LLM bot to review this as well.