-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix AgentSet iteration fails on Python 3.14 with "dictionary changed size during iteration- Issue #2896 #2897
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
Conversation
- Fix GroupBy.__iter__ to iterate over groups.items() instead of non-existent _agents
for more information, see https://pre-commit.ci
|
Performance benchmarks:
|
|
@madhavik-2005 Thanks!
|
for more information, see https://pre-commit.ci
This reverts commit 3ee9049.
|
Hi @tpike3, I've fixed the docstring issue. I had accidentally removed part of the docstring that pre-commit had added. The full docstring is now back in place: """Iterate over (group_name, group) tuples. Yields: The pre-commit checks should pass now. Please let me know if there are any other changes needed - I'm still learning the contribution workflow and appreciate your guidance! |
|
I think I made a mistake, and filled this bug wrongly. I think it's actually not at our end, but Solara's: widgetti/solara#1107. See also #2843. Sorry, appreciate the effort. |
|
Thanks for the update! Since this issue is actually on Solara’s side, I’ll close this PR and follow the Solara issue (widgetti/solara#1107). Appreciate the guidance! |
|
@EwoutH I’m a beginner and interested in contributing to this project. Is it okay if I start by going through the open issues and try to work on the ones I feel I can solve? I’m happy to learn and can also ask questions if I get stuck. |
|
Sure! It helps if you understand ABM and Mesa itself. In our contributor guide there are some resources. |
Summary
Fixes #2896
This PR fixes the
GroupBy.__iter__method that was causingtest_agentset_groupbyto fail withAttributeError: 'GroupBy' object has no attribute '_agents'.Problem
The
GroupBy.__iter__method was incorrectly trying to accessself._agents.keyrefs(), butGroupBydoesn't have an_agentsattribute. TheGroupByclass stores its data inself.groups(a dictionary), not_agents.Solution
Changed
GroupBy.__iter__to correctly iterate over the groups dictionary:Before:
After:
This now correctly returns (group_name, group) tuples as expected by the test suite and matches how
GroupByis intended to be used.Testing
Added
tests/test_iteration_fix.pywith a test that forces garbage collection during iteration to ensure robustness:Test Results:
Additional Context
This fix ensures that iterating over
GroupByobjects works as intended and prevents the AttributeError that was blocking the test suite.