diff --git a/abses/agents/sequences.py b/abses/agents/sequences.py index 292eea4d..3015fd4e 100644 --- a/abses/agents/sequences.py +++ b/abses/agents/sequences.py @@ -41,7 +41,7 @@ from abses.core.types import HOW_TO_SELECT -class ActorsList(Generic[A], AgentSet): +class ActorsList(AgentSet, Generic[A]): """Extended agent set specifically designed for managing Actor collections. ActorsList extends Mesa's AgentSet with ABSESpy-specific functionality, providing diff --git a/tests/api/test_actorslist_mesa_compat.py b/tests/api/test_actorslist_mesa_compat.py new file mode 100644 index 00000000..0f7def58 --- /dev/null +++ b/tests/api/test_actorslist_mesa_compat.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*-coding:utf-8 -*- +"""Regression tests for ActorsList vs mesa AgentSet MRO. + +mesa 3.5 added ``typing.Generic`` to ``AgentSet.__bases__``. If ``ActorsList`` +is declared as ``class ActorsList(Generic[A], AgentSet)`` Python cannot +linearize the MRO and ``import abses`` fails. Keep ``AgentSet`` first to stay +compatible across mesa 3.1–3.5+. +""" + +from __future__ import annotations + +import typing + +from mesa.agent import AgentSet + + +def test_actorslist_subclasses_agentset() -> None: + """ActorsList must remain a real AgentSet subclass.""" + from abses.agents.sequences import ActorsList + + assert issubclass(ActorsList, AgentSet) + + +def test_actorslist_stays_generic() -> None: + """Generic parameterization ``ActorsList[Actor]`` must still work.""" + from abses.agents.actor import Actor + from abses.agents.sequences import ActorsList + + parameterized = ActorsList[Actor] + assert typing.get_origin(parameterized) is ActorsList + + +def test_agentset_first_in_bases() -> None: + """Guard against regressing to ``(Generic[A], AgentSet)`` base order.""" + from abses.agents.sequences import ActorsList + + assert ActorsList.__bases__[0] is AgentSet