Skip to content

Commit

Permalink
Change warning when setting model.agents to error (#2225)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EwoutH authored Aug 21, 2024
1 parent 3ca9098 commit 2cc8ee5
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import itertools
import random
import warnings
from collections import defaultdict

# mypy
Expand Down Expand Up @@ -89,12 +88,10 @@ def agents(self) -> AgentSet:

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

self._agents = agents
Expand Down

0 comments on commit 2cc8ee5

Please sign in to comment.