Skip to content

Commit

Permalink
model: Initialize _agents attribute on __new__
Browse files Browse the repository at this point in the history
This is to avoid the warning:
```
/projectmesa/mesa-examples/examples/boltzmann_wealth_model_experimental/model.py:53: FutureWarning: The Mesa Model class wasn’t initialized. In the future, you need to explicitly initialize the Model by calling super().__init__() on initialization.
  super().__init__(unique_id, model)
```
So that users won't have to call `super().__init__()` in their model
code.
  • Loading branch information
rht committed Jan 6, 2024
1 parent 811b605 commit d30c58b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Any:
# advance.
obj._seed = random.random() # noqa: S311
obj.random = random.Random(obj._seed)
obj._agents: defaultdict[type, dict] = defaultdict(dict)
return obj

def __init__(self, *args: Any, **kwargs: Any) -> None:
Expand All @@ -65,7 +66,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
self.running = True
self.schedule = None
self.current_id = 0
self._agents: defaultdict[type, dict] = defaultdict(dict)

# Warning flags for current experimental features. These make sure a warning is only printed once per model.
self.agentset_experimental_warning_given = False
Expand Down

0 comments on commit d30c58b

Please sign in to comment.