refactor(validator): unify per-repo config override machinery#1333
Open
plind-junior wants to merge 1 commit into
Open
refactor(validator): unify per-repo config override machinery#1333plind-junior wants to merge 1 commit into
plind-junior wants to merge 1 commit into
Conversation
Collapse the three parallel per-repo config families (eligibility, scoring, time-decay) into one spec-driven mechanism. Each family was added separately (entrius#1293, entrius#1300) by copy-pasting the same resolve -> coerce -> parse -> validate scaffolding. - _FieldSpec declares each overridable field: caster, default constant, range bounds, and an optional note. Three spec tables drive everything. - Generic helpers replace the duplication: _resolve_overrides (was 3 pick-closure resolvers), _coerce_override (was 2), _parse_overrides (was 3 + 6 field-name tuples), _bound_desc/_validate_ranges (was 2 validators with ~15 inline checks). - resolve_*, _parse_*, _validate_*_configs become thin wrappers. Public API and dataclasses unchanged; no downstream caller touched. - Net -134 lines in load_weights.py; a 4th override family is now a ~6-line spec entry instead of ~80 lines of boilerplate. Pure refactor - no behavioral change. Adds 4 tests locking the centralized paths (divisor note, nested time_decay range rejection, inclusive-vs-exclusive bracket rendering). Full suite: 841 passing.
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.
What
Collapses the three parallel per-repo config families in
load_weights.py(eligibility, scoring, time-decay) into one spec-driven mechanism. Each family
was added in a separate PR (#1293, #1300) by copy-pasting the same
resolve → coerce → parse → validate scaffolding, leaving the file at 666 lines
with three identical
pickclosures, two identical coerce functions, threenear-identical parse functions, six field-name tuples, and two hand-written
range validators.
Pure refactor — no behavioral change to scoring, eligibility, or config
loading. The public API (
resolve_eligibility,resolve_scoring,resolve_time_decay, allRepo*Config/Resolved*dataclasses) is unchanged,so no downstream caller is touched.
Changes
_FieldSpec: one declaration per overridable field — caster, defaultconstant, range bounds (inclusive/exclusive), and an optional note (e.g.
"used as a divisor"). Three tables drive everything:
_ELIGIBILITY_SPECS,_TIME_DECAY_SPECS,_SCORING_SPECS._resolve_overrides← threepick-closure resolvers_coerce_override←_coerce_eligibility_value+_coerce_scoring_value_parse_overrides← three parse functions + six field-name tuples_bound_desc/_validate_ranges← two validators with ~15 inline checksresolve_*,_parse_*, and_validate_*_configsare now thin wrappers overthe generic helpers.
load_weights.py. Adding a 4th override family is nowa ~6-line spec-table entry instead of ~80 lines of boilerplate.
Tests
test_load_weights.pylocking the centralized paths: theeligibility divisor case (exclusive-min + "used as a divisor" note), nested
scoring.time_decayrange rejection, and inclusive-vs-exclusive bracketrendering in error messages (
[0, 1]vs(0, 1]).ruff check,ruff format --checkclean;pyrightshows no new errors.