chore: migrate analytics/calibration.py to Pydantic BaseModel — pilot (AC-489, AC-481)#593
Merged
jayscambler merged 2 commits intomainfrom Mar 31, 2026
Merged
Conversation
…, AC-481) Pilot migration: converted 3 dataclasses (CalibrationSample, CalibrationOutcome, CalibrationRound) from @DataClass to Pydantic BaseModel. Eliminates ~78 lines of hand-rolled to_dict/from_dict boilerplate — Pydantic provides model_dump/model_validate natively. Backward-compatible: to_dict() and from_dict() kept as thin aliases so existing callers (CalibrationStore, SpotCheckSampler) don't break. TDD: Added test_pydantic_migration.py with 5 tests verifying model_dump roundtrip, JSON serialization, and nested model handling. Pattern established for remaining ~60 analytics dataclasses.
Merged
3 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.
Summary
Pilot migration of analytics dataclasses to Pydantic BaseModel, establishing the pattern for the remaining ~60 dataclasses with manual to_dict/from_dict.
Problem
295 dataclasses across the codebase implement manual
to_dict() -> dict[str, Any]andfrom_dict(data)classmethods — boilerplate that Pydantic provides for free viamodel_dump()andmodel_validate().Changes
Converted
analytics/calibration.py(3 classes)CalibrationSampleCalibrationOutcomeCalibrationRoundTotal: ~78 lines of boilerplate → 6 lines of aliases
Backward compatibility
to_dict()andfrom_dict()kept as thin aliases (self.model_dump()/cls.model_validate(data)) so existing callers (CalibrationStore,SpotCheckSampler) work unchanged.Pattern for future migrations
TDD
Added
test_pydantic_migration.pywith 5 tests:Verification
ruff check src— all checks passedmypy src— zero errorspytest tests/— all tests passIssues
Partially resolves AC-489 and AC-481