Skip to content

Commit 2cc8ee5

Browse files
authored
Change warning when setting model.agents to error (#2225)
Replaced the warning with an `AttributeError` when attempting to set `model.agents`. This change enforces that the `agents` attribute will be reserved for internal use by Mesa in future releases. Users must update their code to use a different attribute name for custom agent storage.
1 parent 3ca9098 commit 2cc8ee5

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

mesa/model.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import itertools
1212
import random
13-
import warnings
1413
from collections import defaultdict
1514

1615
# mypy
@@ -89,12 +88,10 @@ def agents(self) -> AgentSet:
8988

9089
@agents.setter
9190
def agents(self, agents: Any) -> None:
92-
warnings.warn(
93-
"You are trying to set model.agents. In a next release, this attribute is used "
94-
"by MESA itself so you cannot use it directly anymore."
95-
"Please adjust your code to use a different attribute name for custom agent storage",
96-
UserWarning,
97-
stacklevel=2,
91+
raise AttributeError(
92+
"You are trying to set model.agents. In Mesa 3.0 and higher, this attribute will be "
93+
"used by Mesa itself, so you cannot use it directly anymore."
94+
"Please adjust your code to use a different attribute name for custom agent storage."
9895
)
9996

10097
self._agents = agents

0 commit comments

Comments
 (0)