Skip to content

Commit 67c4a28

Browse files
committed
Require Mesa models to be initialized with super.__init__()
Remove the workaround for when the model super has not been called, and thereby require Mesa models to be initialized with `super.__init__()`. This warning was present since 2.3.0, so there has been some time to update for existing users.
1 parent 60779be commit 67c4a28

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

mesa/agent.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import contextlib
1212
import copy
1313
import operator
14-
import warnings
1514
import weakref
16-
from collections import defaultdict
1715
from collections.abc import Callable, Iterable, Iterator, MutableSet, Sequence
1816
from random import Random
1917

@@ -50,19 +48,7 @@ def __init__(self, unique_id: int, model: Model) -> None:
5048
self.pos: Position | None = None
5149

5250
# register agent
53-
try:
54-
self.model.agents_[type(self)][self] = None
55-
except AttributeError:
56-
# model super has not been called
57-
self.model.agents_ = defaultdict(dict)
58-
self.model.agents_[type(self)][self] = None
59-
self.model.agentset_experimental_warning_given = False
60-
61-
warnings.warn(
62-
"The Mesa Model class was not initialized. In the future, you need to explicitly initialize the Model by calling super().__init__() on initialization.",
63-
FutureWarning,
64-
stacklevel=2,
65-
)
51+
self.model.agents_[type(self)][self] = None
6652

6753
def remove(self) -> None:
6854
"""Remove and delete the agent from the model."""
@@ -100,8 +86,6 @@ class AgentSet(MutableSet, Sequence):
10086
which means that agents not referenced elsewhere in the program may be automatically removed from the AgentSet.
10187
"""
10288

103-
agentset_experimental_warning_given = False
104-
10589
def __init__(self, agents: Iterable[Agent], model: Model):
10690
"""
10791
Initializes the AgentSet with a collection of agents and a reference to the model.

0 commit comments

Comments
 (0)