Skip to content

Commit 2c17215

Browse files
SongshGeoclaude
andcommitted
fix(agents): 🐛 Swap ActorsList base order to fix mesa 3.5 MRO error
mesa 3.5 added typing.Generic to AgentSet's bases, so declaring ActorsList as (Generic[A], AgentSet) made the MRO unlinearizable and broke `import abses`. Put AgentSet first to stay compatible with mesa 3.1-3.5+, and add regression tests guarding the base order. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c92eefd commit 2c17215

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

abses/agents/sequences.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from abses.core.types import HOW_TO_SELECT
4242

4343

44-
class ActorsList(Generic[A], AgentSet):
44+
class ActorsList(AgentSet, Generic[A]):
4545
"""Extended agent set specifically designed for managing Actor collections.
4646
4747
ActorsList extends Mesa's AgentSet with ABSESpy-specific functionality, providing
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
# -*-coding:utf-8 -*-
3+
"""Regression tests for ActorsList vs mesa AgentSet MRO.
4+
5+
mesa 3.5 added ``typing.Generic`` to ``AgentSet.__bases__``. If ``ActorsList``
6+
is declared as ``class ActorsList(Generic[A], AgentSet)`` Python cannot
7+
linearize the MRO and ``import abses`` fails. Keep ``AgentSet`` first to stay
8+
compatible across mesa 3.1–3.5+.
9+
"""
10+
11+
from __future__ import annotations
12+
13+
import typing
14+
15+
from mesa.agent import AgentSet
16+
17+
18+
def test_actorslist_subclasses_agentset() -> None:
19+
"""ActorsList must remain a real AgentSet subclass."""
20+
from abses.agents.sequences import ActorsList
21+
22+
assert issubclass(ActorsList, AgentSet)
23+
24+
25+
def test_actorslist_stays_generic() -> None:
26+
"""Generic parameterization ``ActorsList[Actor]`` must still work."""
27+
from abses.agents.actor import Actor
28+
from abses.agents.sequences import ActorsList
29+
30+
parameterized = ActorsList[Actor]
31+
assert typing.get_origin(parameterized) is ActorsList
32+
33+
34+
def test_agentset_first_in_bases() -> None:
35+
"""Guard against regressing to ``(Generic[A], AgentSet)`` base order."""
36+
from abses.agents.sequences import ActorsList
37+
38+
assert ActorsList.__bases__[0] is AgentSet

0 commit comments

Comments
 (0)