evals: resolve the EvalCase parameter statically, not by value scan#129
Merged
Conversation
The wrapper used to rediscover the case at runtime by scanning kwargs values with isinstance(_, EvalCase), while the registration guard read type hints - two sources of truth that could disagree. A parameter not annotated as EvalCase whose fixture returns one at runtime slipped past the registration guard, and the value scan would then silently pick whichever EvalCase came first in kwargs order, misattributing its name/expected/inputs (issue #120). Resolve which parameter carries the case once, at decoration time (_resolve_case_param), and do a direct kwargs[name] lookup at runtime. A parameter qualifies as the case when its declared type is an EvalCase, or when it is bound via From(source) whose source yields EvalCase instances (covers the loose Annotated[Any, From(cases)] form). More than one qualifying parameter still raises MultipleEvalCaseParamsError at registration. This collapses the registration guard, the runtime guard, and the value scan into a single static source of truth: the case is identified by which parameter it is, so an EvalCase merely returned on an unrelated parameter can no longer be mistaken for the case. Removes _find_case, the _extract_* value scanners, and _validate_single_evalcase_param. Closes #120
renaudcepre
force-pushed
the
fix-runtime-evalcase-guard
branch
from
June 15, 2026 20:22
f4fd790 to
1e3660e
Compare
renaudcepre
added a commit
that referenced
this pull request
Jun 25, 2026
…129) The wrapper used to rediscover the case at runtime by scanning kwargs values with isinstance(_, EvalCase), while the registration guard read type hints - two sources of truth that could disagree. A parameter not annotated as EvalCase whose fixture returns one at runtime slipped past the registration guard, and the value scan would then silently pick whichever EvalCase came first in kwargs order, misattributing its name/expected/inputs (issue #120). Resolve which parameter carries the case once, at decoration time (_resolve_case_param), and do a direct kwargs[name] lookup at runtime. A parameter qualifies as the case when its declared type is an EvalCase, or when it is bound via From(source) whose source yields EvalCase instances (covers the loose Annotated[Any, From(cases)] form). More than one qualifying parameter still raises MultipleEvalCaseParamsError at registration. This collapses the registration guard, the runtime guard, and the value scan into a single static source of truth: the case is identified by which parameter it is, so an EvalCase merely returned on an unrelated parameter can no longer be mistaken for the case. Removes _find_case, the _extract_* value scanners, and _validate_single_evalcase_param. Closes #120 Co-authored-by: Claude <noreply@anthropic.com>
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
Closes #120 — addresses it structurally rather than with a runtime backstop (per discussion).
The design problem
The wrapper had two sources of truth for "which parameter carries the case":
_validate_single_evalcase_param)_find_case,isinstance(v, EvalCase))They could disagree. A parameter not annotated as
EvalCasewhose fixture returns one at runtime (e.g.Annotated[Database, Use(db)]) was invisible to the registration guard but visible to the value scan — which then silently picked whicheverEvalCasecame first in kwargs order, misattributing its name/expected/inputs.The information was already known statically: the case is injected by the DI layer under a specific parameter name. The runtime didn't need to rediscover it by value.
Change
Resolve which parameter carries the case once, at decoration time (
_resolve_case_param), and do a directkwargs[name]lookup at runtime. A parameter qualifies as the case when:EvalCase(subclass) —case: EvalCase,Annotated[EvalCase, From(cases)]; orFrom(source)whose source yieldsEvalCaseinstances — covers the deliberately looseAnnotated[Any, From(cases)]form.More than one qualifying parameter still raises
MultipleEvalCaseParamsErrorat registration.This collapses the registration guard, the runtime guard, and the value scan into one static source of truth: the case is identified by which parameter it is. An
EvalCasemerely returned on an unrelated parameter can no longer be mistaken for the case — issue #120 becomes structurally impossible instead of guarded-against.Removes
_find_case, the_extract_*value scanners, and_validate_single_evalcase_param.Tests
tests/evals/test_multiple_evalcase_params.pyrewritten around the new contract:Fromcase params accepted;From) rejected at registration;EvalCasereturned on an unrelated parameter is ignored, not misattributed;Fromover non-EvalCaseitems (e.g. dicts) is parametrization, not a case (falls back to the function name).Full suite: 1246 passed,
ruffclean,mypy --strictclean.