Context
#189 added execution_context fields to two dataclasses with loose typing:
packages/darnit/src/darnit/sieve/handler_registry.py:104:
execution_context: Any | None = None
packages/darnit/src/darnit/sieve/models.py:55:
execution_context: Optional["ExecutionContext"] = None # already uses forward ref
The CheckContext side uses a proper "ExecutionContext" forward reference (wrapped in TYPE_CHECKING), but HandlerContext uses Any | None. This means custom handler authors lose type-check assistance when calling handler_ctx.execution_context.get_or_run_tool(...).
Proposal
Change HandlerContext.execution_context to use a proper forward reference matching CheckContext:
if TYPE_CHECKING:
from darnit.core.models import ExecutionContext
@dataclass
class HandlerContext:
...
execution_context: "ExecutionContext | None" = None
Why the loose typing was chosen
Likely to avoid a circular import between sieve/handler_registry.py and core/models.py. TYPE_CHECKING + string annotation is the standard workaround and is already used in sieve/models.py.
Acceptance criteria
HandlerContext.execution_context type is tightened to ExecutionContext | None
- No runtime circular import introduced
mypy/pyright can infer .get_or_run_tool() on the attribute
- Existing tests still pass
References
Context
#189 added
execution_contextfields to two dataclasses with loose typing:packages/darnit/src/darnit/sieve/handler_registry.py:104:packages/darnit/src/darnit/sieve/models.py:55:The
CheckContextside uses a proper"ExecutionContext"forward reference (wrapped inTYPE_CHECKING), butHandlerContextusesAny | None. This means custom handler authors lose type-check assistance when callinghandler_ctx.execution_context.get_or_run_tool(...).Proposal
Change
HandlerContext.execution_contextto use a proper forward reference matchingCheckContext:Why the loose typing was chosen
Likely to avoid a circular import between
sieve/handler_registry.pyandcore/models.py.TYPE_CHECKING+ string annotation is the standard workaround and is already used insieve/models.py.Acceptance criteria
HandlerContext.execution_contexttype is tightened toExecutionContext | Nonemypy/pyrightcan infer.get_or_run_tool()on the attributeReferences