Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[Feature]: Enforce Abstract↔Concrete type-hint coherence via a metaclass

Đang mở
#149 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
tooling

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ả

feature
🤔 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
  1. Add a new metaclass (e.g. InterfaceMeta) in a util module (say mesa_frames.utils.interface_meta) that, in its __init__, walks every ABC base and uses Beartype’s is_subhint to compare each abstract method’s type hints against the override in the subclass—raising a TypeError at class‐definition time on mismatch.
  2. Switch our ABCs (like AgentContainer) to use metaclass=InterfaceMeta instead of plain ABCMeta. Any drop-in mismatch in AgentSetPolars (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
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

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 mesa/mesa-frames

Tất cả issue của mesa/mesa-frames

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.