Skip to content

Commit

Permalink
Model: Replace get_agents_of_type method with agents_by_type property
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutH committed Sep 2, 2024
1 parent 0a1b2a3 commit fce03b1
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,16 @@ def agent_types(self) -> list[type]:
"""Return a list of all unique agent types registered with the model."""
return list(self._agents_by_type.keys())

def agents_of_type(self, agenttype: type[Agent]) -> AgentSet:
"""Retrieves an AgentSet containing all agents of the specified type.
Args:
agenttype: The type of agent to retrieve.
Raises:
KeyError: If agenttype does not exist
"""
return self._agents_by_type[agenttype]
@property
def agents_by_type(self) -> dict[type[Agent], AgentSet]:
"""A dictionary where the keys are agent types and the values are the corresponding AgentSets."""
return self._agents_by_type

def get_agents_of_type(self, agenttype: type[Agent]) -> AgentSet:
"""Deprecated: Retrieves an AgentSet containing all agents of the specified type."""
warnings.warn(
"get_agents_of_type is deprecated, please use agents_of_type instead.",
f"Model.get_agents_of_type() is deprecated, please replace get_agents_of_type({agenttype})"
f"with the property agents_by_type[{agenttype}].",
DeprecationWarning,
stacklevel=2,
)
Expand Down

0 comments on commit fce03b1

Please sign in to comment.