[Feature]: Enforce Abstract↔Concrete type-hint coherence via a metaclass
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách đọc mesa_frames/abstract/agents.py và mesa_frames/concrete/agentset.py, sau đó xem xét entry point mesa_frames.utils.interface_meta được đề xuất và hành vi is_subhint của Beartype. Công việc hoàn tất khi các ABCs sử dụng metaclass mới và các type hint cụ thể không tương thích gây ra TypeError tại thời điểm định nghĩa class với thông báo lỗi rõ ràng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
🤔 Problem Description
After merging PR #143, we will have Beartype on every method, but nothing automatically verifies that each concrete class still honors the abstract class’s type hints.
A small drift—e.g. changing an add(...) signature—can silently break downstream code or introduce subtle variance bugs that only fail at runtime.
💡 Proposed Solution
- Add a new metaclass (e.g.
InterfaceMeta) in a util module (saymesa_frames.utils.interface_meta) that, in its__init__, walks everyABCbase and uses Beartype’sis_subhintto compare each abstract method’s type hints against the override in the subclass—raising aTypeErrorat class‐definition time on mismatch. - Switch our ABCs (like
AgentContainer) to usemetaclass=InterfaceMetainstead of plainABCMeta. Any drop-in mismatch inAgentSetPolars(or any other subclass) will now fail immediately when Python imports the module, giving a clear error message.
Example in mesa-frames
# mesa_frames/abstract/agents.py
from abc import abstractmethod
from typing import get_type_hints
from typing_extensions import Self
from mesa_frames.types_ import DataFrameInput
from collections.abc import Collection
…
class AgentSetDF(AgentContainer, DataFrameMixin):
@abstractmethod
def add(
self,
agents: DataFrameInput,
inplace: bool = True,
) -> Self:
"""Add agents to the container."""
…
# mesa_frames/concrete/agentset.py
import polars as pl
from typing import Sequence, Any
from mesa_frames.abstract.agents import AgentSetDF
from mesa_frames.utils.interface_meta import InterfaceMeta
class AgentSetPolars(AgentSetDF, PolarsMixin, metaclass=InterfaceMeta):
def add(
self,
agents: pl.DataFrame | Sequence[Any] | dict[str, Any],
inplace: bool = True,
) -> Self:
"""Polars-backed add implementation."""
…
Here, the metaclass check would ensure that the concrete add’s agents: hint (pl.DataFrame | Sequence[Any] | dict[str,Any]) is a valid superhint of the abstract DataFrameInput alias (dict[str, Any] | Sequence[Sequence] | pl.DataFrame), and would error out at class‐definition time if someone ever drifted one side out of alignment.
🔄 Alternatives Considered
- Decorator (opt-in per class), but easy to forget.
- CI test to compare signatures, but that only catches errors later in testing.
➕ Additional Context
- Abstract:
mesa_frames/abstract/agents.py - Concrete:
mesa_frames/concrete/agentset.py
- Ngôn ngữ chính
- Python
- Star
- 44
- Fork
- 20
- Merge trung bình
- 1 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của mesa/mesa-frames
-
Mesa-frames 0.2.0Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
mesa/mesa-frames#186 · 10 bình luận ·
-
feature triage
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
mesa/mesa-frames#177 · 1 bình luận ·
-
[Bug]: Solving polars Deprecation warnings for `is_in`Có thể đã có người làm @adamamer20 đã nhận 425 ngày trước. Đang mởbug good first issue maintenance Sprints!
mesa/mesa-frames#174 · 2 bình luận · 1 người được giao ·
-
[Enhancement] : agents selection in AgentsDf would be better if it returns agent_idx/name as keyĐang mởenhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 40/100
mesa/mesa-frames#162 · 1 bình luận ·
-
[Feature]: Easy seed accessor across the entire codebaseCó thể làm lại được @falloficaruss đã nhận 324 ngày trước và không có pull request nào đang mở. Đang mởfeature good first issue Sprints!
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
mesa/mesa-frames#159 · 3 bình luận ·
Tất cả issue của mesa/mesa-frames
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
Validate finite output clamping limits in StepPredictor.prepare_clamping_params to prevent silent NaN/Inf propagationCó thể đã có người làm @muskan-creates352 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
mllam/neural-lam#848 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
infra
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
fab-geocommuns/RNB-coeur#1166 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
deepspeedai/DeepSpeed#8951 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
aws/context-ontology-accelerator#343 ·
Maintainer thường phản hồi trong vòng 1 ngày