Skip to content

chore(lint): enable ruff F821 (undefined name) - #4780

Merged
springfall2008 merged 1 commit into
mainfrom
chore/ruff-f821
Aug 27, 2026
Merged

chore(lint): enable ruff F821 (undefined name)#4780
springfall2008 merged 1 commit into
mainfrom
chore/ruff-f821

Conversation

@chalfontchubby

Copy link
Copy Markdown
Collaborator

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's rate_text_scan() read rate_range on 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 that get_rate_text(minutes_now) always equals the initial rate_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: initialised rate_range before the loop.

The function had no test coverage at all, so added tests/test_rate_text_scan.py covering a 3-band tariff.

Test plan

  • New rate_text_scan test passes
  • ./run_pre_commit passes
  • Full quick test suite passes

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.
Base automatically changed from chore/ruff-e722 to main August 27, 2026 17:41
@springfall2008
springfall2008 merged commit 1102edc into main Aug 27, 2026
2 checks passed
@springfall2008
springfall2008 deleted the chore/ruff-f821 branch August 27, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants