Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model: Initialize _agents attribute on __new__ #1937

Closed
wants to merge 2 commits into from

Conversation

rht
Copy link
Contributor

@rht rht commented Jan 6, 2024

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.

Copy link

codecov bot commented Jan 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (811b605) 79.96% compared to head (4b84a55) 79.96%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1937   +/-   ##
=======================================
  Coverage   79.96%   79.96%           
=======================================
  Files          15       15           
  Lines        1143     1143           
  Branches      245      245           
=======================================
  Hits          914      914           
  Misses        199      199           
  Partials       30       30           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.
@rht rht force-pushed the agentset_model_new branch from d30c58b to 4ce3459 Compare January 6, 2024 00:28
@EwoutH
Copy link
Member

EwoutH commented Jan 6, 2024

Looks useful, thanks! I don’t have the Python expertise to judge the code changes, but high-level, I approve!


Not necessary for this PR, but maybe we should also consider on a broader spectrum if we want to require super().__init__() calls on initializing a subclass of the Agent or the Model. Can’t we just move everything to __new__? I started a discussion on this here:

@rht
Copy link
Contributor Author

rht commented Jan 6, 2024

Closing because self._agents is attribute initialization, which has to be located in __init__. No exception.

@rht rht closed this Jan 6, 2024
@rht rht deleted the agentset_model_new branch January 6, 2024 12:11
@rht rht restored the agentset_model_new branch January 6, 2024 12:11
@rht rht deleted the agentset_model_new branch January 6, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants