Problem
EvalResult.scores is typed as dict[str, float | None] (framework.py:104). Because dict is invariant in both key and value types, constructing an EvalResult with dict[str, float] (no None values) is rejected by type checkers:
# Type error: dict[str, float] is not assignable to dict[str, float | None]
result = EvalResult(input=..., output=..., scores={"accuracy": 0.95})
This is the same invariance class as #280 (EvalParameters) and the Metadata alias.
Why this one is different
EvalResult is a dataclass, not a function parameter. The type annotation serves as both the constructor parameter type and the attribute type. Simply changing to Mapping[str, float | None] would:
- Fix the constructor, but
- Change the attribute type to read-only, which could break internal code that mutates
scores after construction
Options
- Accept
Mapping in a custom __init__, store as dict — most correct, but adds boilerplate to a dataclass
- Change to
Mapping[str, float | None] — if the framework never mutates scores after construction (needs verification)
- Document as output-only — if callers are not expected to construct
EvalResult directly
Context
Related PRs: #281 (EvalParameters → Mapping), #285 (Metadata/ParametersSchema → Mapping)
Problem
EvalResult.scoresis typed asdict[str, float | None](framework.py:104). Becausedictis invariant in both key and value types, constructing anEvalResultwithdict[str, float](no None values) is rejected by type checkers:This is the same invariance class as #280 (
EvalParameters) and theMetadataalias.Why this one is different
EvalResultis a dataclass, not a function parameter. The type annotation serves as both the constructor parameter type and the attribute type. Simply changing toMapping[str, float | None]would:scoresafter constructionOptions
Mappingin a custom__init__, store asdict— most correct, but adds boilerplate to a dataclassMapping[str, float | None]— if the framework never mutatesscoresafter construction (needs verification)EvalResultdirectlyContext
Related PRs: #281 (EvalParameters → Mapping), #285 (Metadata/ParametersSchema → Mapping)