chore(lint): enable ruff F821 (undefined name) - #4780
Merged
Conversation
Ruff couldn't prove rate_range is always assigned before its first read - the invariant holds (get_rate_text(minutes_now) always equals the initial rate_text, so the append branch never fires on iteration 1) but isn't visible to static analysis. Verified the function's min/max grouping logic itself is correct against 2000 randomised trials before making this change - it's a lint fix, not a behaviour change. Added test_rate_text_scan.py since the function had no coverage. Part of the #2198 linter-complaint cleanup.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enables ruff's F821 rule (undefined name) and fixes the 1 site it caught. Stacked on #4779, part of the rule-by-rule cleanup from #2198.
Summary
output.py'srate_text_scan()readrate_rangeon a band-transition append before that iteration had assigned it - relying on the previous iteration's value having been set. I verified the function's min/max grouping logic is actually correct (2000 randomised trials against a naive ground-truth implementation, zero mismatches) - the invariant that saves it is thatget_rate_text(minutes_now)always equals the initialrate_text, so the append branch never fires on iteration 1. Ruff can't see that invariant, so this is a lint fix, not a behaviour change: initialisedrate_rangebefore the loop.The function had no test coverage at all, so added
tests/test_rate_text_scan.pycovering a 3-band tariff.Test plan
rate_text_scantest passes./run_pre_commitpasses