Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion abses/agents/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions tests/api/test_actorslist_mesa_compat.py
Original file line number Diff line number Diff line change
@@ -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
Loading