From 42af43923ca5d0d72dd01382602db9383039e4ff Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Mon, 19 Aug 2024 15:53:09 +0200 Subject: [PATCH 1/2] Change warning when setting model.agents to error 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. --- mesa/model.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mesa/model.py b/mesa/model.py index d998e112f26..d354a210fc7 100644 --- a/mesa/model.py +++ b/mesa/model.py @@ -89,12 +89,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 From 776faef3458cee9a4c2805f7a99c26085e8295ab Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 13:58:16 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mesa/model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mesa/model.py b/mesa/model.py index d354a210fc7..bcd5902f2eb 100644 --- a/mesa/model.py +++ b/mesa/model.py @@ -10,7 +10,6 @@ import itertools import random -import warnings from collections import defaultdict # mypy