Skip to content

Commit fce03b1

Browse files
committed
Model: Replace get_agents_of_type method with agents_by_type property
1 parent 0a1b2a3 commit fce03b1

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

mesa/model.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,16 @@ def agent_types(self) -> list[type]:
106106
"""Return a list of all unique agent types registered with the model."""
107107
return list(self._agents_by_type.keys())
108108

109-
def agents_of_type(self, agenttype: type[Agent]) -> AgentSet:
110-
"""Retrieves an AgentSet containing all agents of the specified type.
111-
112-
Args:
113-
agenttype: The type of agent to retrieve.
114-
115-
Raises:
116-
KeyError: If agenttype does not exist
117-
118-
119-
"""
120-
return self._agents_by_type[agenttype]
109+
@property
110+
def agents_by_type(self) -> dict[type[Agent], AgentSet]:
111+
"""A dictionary where the keys are agent types and the values are the corresponding AgentSets."""
112+
return self._agents_by_type
121113

122114
def get_agents_of_type(self, agenttype: type[Agent]) -> AgentSet:
123115
"""Deprecated: Retrieves an AgentSet containing all agents of the specified type."""
124116
warnings.warn(
125-
"get_agents_of_type is deprecated, please use agents_of_type instead.",
117+
f"Model.get_agents_of_type() is deprecated, please replace get_agents_of_type({agenttype})"
118+
f"with the property agents_by_type[{agenttype}].",
126119
DeprecationWarning,
127120
stacklevel=2,
128121
)

0 commit comments

Comments
 (0)