Tighten execution_context typing from Any to proper forward reference

オープン 初心者向け
#195 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
リファクタリング
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python
領域
backend

調査の方向性

packages/darnit/src/darnit/sieve/models.py にある ExecutionContext の既存の前方参照パターンを読み、その後 packages/darnit/src/darnit/sieve/handler_registry.py の HandlerContext.execution_context を更新してください。既存のテストを実行し、mypy または pyright で確認してください。属性が ExecutionContext | None として型付けされ、.get_or_run_tool() が推論され、実行時の循環インポートが導入されないことを完了条件とします。

索引モデルが issue の本文から書いたものです。

説明

module-core

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

  • Introduced by: #189
  • Related: #194 (wiring first real consumer)
主要言語
Python
スター
22
フォーク
27
平均マージ
4日 20時間
マージ済み PR(30日)
75

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

darnitdevorg/darnit のほかの issue

darnitdevorg/darnit の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。