Skip to content

Commit 3a0d270

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a962599 commit 3a0d270

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

mesa/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,4 +712,4 @@ def __iter__(self) -> Iterator[tuple[Hashable, list | AgentSet]]:
712712
return iter(self.groups.items())
713713

714714
def __len__(self): # noqa: D105
715-
return len(self.groups)
715+
return len(self.groups)

tests/test_iteration_fix.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
"""Test AgentSet iteration with garbage collection (Python 3.14 fix)."""
22

33
import gc
4+
45
from mesa.agent import Agent, AgentSet
56
from mesa.model import Model
67

78

89
class TestAgent(Agent):
910
"""Simple agent for testing."""
10-
pass
1111

1212

1313
def test_agentset_iteration_with_gc():
1414
"""Test that AgentSet iteration doesn't fail when GC runs during iteration."""
1515
model = Model()
1616
agents = [TestAgent(model) for _ in range(100)]
1717
agentset = AgentSet(agents, random=model.random)
18-
18+
1919
# Test iteration with forced GC
2020
collected_ids = []
2121
for i, agent in enumerate(agentset):
2222
collected_ids.append(agent.unique_id)
2323
if i % 10 == 0:
2424
gc.collect() # Force GC during iteration
25-
25+
2626
assert len(collected_ids) == 100
2727
print("Test passed: Iteration with GC works!")
2828

2929

3030
if __name__ == "__main__":
3131
test_agentset_iteration_with_gc()
32-
print("\nAll tests passed!")
32+
print("\nAll tests passed!")

0 commit comments

Comments
 (0)