[Feature]: Enforce Abstract↔Concrete type-hint coherence via a metaclass
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
Línea de trabajo
Empieza leyendo mesa_frames/abstract/agents.py y mesa_frames/concrete/agentset.py; después revisa el punto de entrada propuesto mesa_frames.utils.interface_meta y el comportamiento de is_subhint de Beartype. El trabajo estará terminado cuando las ABCs utilicen la nueva metaclase y las sugerencias de tipo concretas incompatibles provoquen un TypeError en el momento de definir la clase, con un mensaje de error claro.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
🤔 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
- Lenguaje dominante
- Python
- Estrellas
- 43
- Forks
- 19
- Merge medio
- 1 min
- PR fusionados (30 d)
- 1
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de mesa/mesa-frames
-
Mesa-frames 0.2.0Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
mesa/mesa-frames#186 · 10 comentarios ·
-
feature triage
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
mesa/mesa-frames#177 · 1 comentario ·
-
[Bug]: Solving polars Deprecation warnings for `is_in`Posiblemente ocupada @adamamer20 la tomó hace 410 días. Abiertobug good first issue maintenance Sprints!
mesa/mesa-frames#174 · 2 comentarios · 1 asignado ·
-
[Enhancement] : agents selection in AgentsDf would be better if it returns agent_idx/name as keyAbiertoenhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 40/100
mesa/mesa-frames#162 · 1 comentario ·
-
[Feature]: Easy seed accessor across the entire codebaseQuizá libre de nuevo @falloficaruss la tomó hace 309 días y no hay ningún pull request abierto. Abiertofeature good first issue Sprints!
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
mesa/mesa-frames#159 · 3 comentarios ·
Todos los issues de mesa/mesa-frames
Issues similares
-
good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
btclib-org/btclib-node#1955 ·
Los mantenedores suelen responder en 1 día
-
documentation v0.9.2
Dificultad 2/5 Medio día Aptitud para principiantes 72/100
khuisman/mcp-gee-sweet#1033 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ossf/cve-bin-tool#5966 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 2 días
-
write_iceberg ignores the table's write.parquet.compression-codec propertyPosiblemente ocupada @YuangGao la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Eventual-Inc/Daft#7606 ·
Los mantenedores suelen responder en 1 día