fix: use Mapping instead of dict for EvalResult.scores#360
Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit intomainfrom Apr 28, 2026
Merged
fix: use Mapping instead of dict for EvalResult.scores#360Abhijeet Prasad (AbhiPrasad) merged 1 commit intomainfrom
Mapping instead of dict for EvalResult.scores#360Abhijeet Prasad (AbhiPrasad) merged 1 commit intomainfrom
Conversation
`EvalResult.scores` was typed as `dict[str, float | None]`, but `dict` is invariant in its value type. Callers constructing the dataclass with a homogeneous `dict[str, float]` (no None values) get a type error from both pyright and mypy. The framework only iterates `result.scores.items()` (in `build_local_summary`) and never mutates `scores` after construction, so widening the annotation to `Mapping[str, float | None]` is safe and matches the pattern already applied to `EvalParameters` (#281) and `Metadata`/`ParametersSchema` (#285). Fixes #292 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Abhijeet Prasad (AbhiPrasad)
approved these changes
Apr 28, 2026
Merged
Abhijeet Prasad (AbhiPrasad)
added a commit
that referenced
this pull request
Apr 29, 2026
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
EvalResult.scoresis typed asdict[str, float | None], butdictis invariant in its value type, so callers constructing anEvalResultwith a homogeneousdict[str, float](noNonevalues) get a type error from both pyright and mypy:This PR widens the annotation from
dict[str, float | None]toMapping[str, float | None]. The framework only iteratesresult.scores.items()inbuild_local_summaryand never mutatesscoresafter construction, soMappingis the correct abstraction. Same fix pattern as #281 (EvalParameters) and #285 (Metadata/ParametersSchema).Mappingis already imported.Fixes #292.
Test plan
0 errors, 0 warningsSuccess: no issues foundsrc/braintrust/type_tests/: cleanpytest src/braintrust/test_framework.py: 35 passed, 1 skippedruff check+ pre-commit hooks onframework.py: cleanEval(...)against the live Braintrust API with mixedfloat/Nonescorer outputs: results and summary unchanged ({'exact_match': 1.0, 'always_none': None}, summary100%)🤖 Generated with Claude Code