Tighten execution_context typing from Any to proper forward reference

Đang mở Phù hợp với người mới
#195 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Đọc mẫu tham chiếu trước hiện có của ExecutionContext trong packages/darnit/src/darnit/sieve/models.py, sau đó cập nhật HandlerContext.execution_context trong packages/darnit/src/darnit/sieve/handler_registry.py. Chạy các bài kiểm tra hiện có và kiểm tra bằng mypy hoặc pyright. Công việc được xem là hoàn tất khi thuộc tính được khai báo kiểu là ExecutionContext | None, .get_or_run_tool() được suy luận kiểu và không phát sinh import vòng tròn khi chạy.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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)
Ngôn ngữ chính
Python
Star
22
Fork
27
Merge trung bình
4 ngày 20 giờ
Pull request đã merge (30 ngày)
75

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của darnitdevorg/darnit

Tất cả issue của darnitdevorg/darnit

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.