diff --git a/mesa/agent.py b/mesa/agent.py index 2f0e842d382..91655784f79 100644 --- a/mesa/agent.py +++ b/mesa/agent.py @@ -11,9 +11,7 @@ import contextlib import copy import operator -import warnings import weakref -from collections import defaultdict from collections.abc import Callable, Iterable, Iterator, MutableSet, Sequence from random import Random @@ -52,17 +50,11 @@ def __init__(self, unique_id: int, model: Model) -> None: # register agent try: self.model.agents_[type(self)][self] = None - except AttributeError: + except AttributeError as err: # model super has not been called - self.model.agents_ = defaultdict(dict) - self.model.agents_[type(self)][self] = None - self.model.agentset_experimental_warning_given = False - - warnings.warn( - "The Mesa Model class was not initialized. In the future, you need to explicitly initialize the Model by calling super().__init__() on initialization.", - FutureWarning, - stacklevel=2, - ) + raise RuntimeError( + "The Mesa Model class was not initialized. You must explicitly initialize the Model by calling super().__init__() on initialization." + ) from err def remove(self) -> None: """Remove and delete the agent from the model.""" @@ -100,8 +92,6 @@ class AgentSet(MutableSet, Sequence): which means that agents not referenced elsewhere in the program may be automatically removed from the AgentSet. """ - agentset_experimental_warning_given = False - def __init__(self, agents: Iterable[Agent], model: Model): """ Initializes the AgentSet with a collection of agents and a reference to the model. diff --git a/mesa/space.py b/mesa/space.py index a6d070f0291..39433cb3fad 100644 --- a/mesa/space.py +++ b/mesa/space.py @@ -586,7 +586,7 @@ class PropertyLayer: aggregate_property(operation): Performs an aggregate operation over all cells. """ - agentset_experimental_warning_given = False + propertylayer_experimental_warning_given = False def __init__( self, name: str, width: int, height: int, default_value, dtype=np.float64 @@ -633,14 +633,14 @@ def __init__( self.data = np.full((width, height), default_value, dtype=dtype) - if not self.__class__.agentset_experimental_warning_given: + if not self.__class__.propertylayer_experimental_warning_given: warnings.warn( "The new PropertyLayer and _PropertyGrid classes experimental. It may be changed or removed in any and all future releases, including patch releases.\n" "We would love to hear what you think about this new feature. If you have any thoughts, share them with us here: https://github.com/projectmesa/mesa/discussions/1932", FutureWarning, stacklevel=2, ) - self.__class__.agentset_experimental_warning_given = True + self.__class__.propertylayer_experimental_warning_given = True def set_cell(self, position: Coordinate, value): """