From f16a714e8d499ab1c57e91cb592e4494e18078f7 Mon Sep 17 00:00:00 2001 From: "Nova (SFK)" Date: Tue, 28 Apr 2026 02:40:39 +0000 Subject: [PATCH] fix: use `Mapping` instead of `dict` for `EvalResult.scores` `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 --- py/src/braintrust/framework.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/src/braintrust/framework.py b/py/src/braintrust/framework.py index 554e4007..84a504aa 100644 --- a/py/src/braintrust/framework.py +++ b/py/src/braintrust/framework.py @@ -100,7 +100,7 @@ class EvalResult(SerializableDataClass, Generic[Input, Output, Expected]): input: Input output: Output - scores: dict[str, float | None] + scores: Mapping[str, float | None] classifications: dict[str, list[ClassificationItem]] | None = None expected: Expected | None = None metadata: Metadata | None = None