Bug: Cell.is_full type comparison error with capacity=None
Describe the bug The Cell.is_full property compares an integer to None when checking if a cell with infinite capacity is full. This happens because cells default to capacity=None for infinite capacity, and the code does len(self.agents) == self.capacity , which evaluates to something like 100 == None. While this returns the correct result (False), it's a type comparison error that violates type safety.
Location: mesa/discrete_space/cell.py lines 135-137
Expected behavior The method should explicitly handle the None case instead of relying on int-to-None comparison. When capacity=None, it should return False without comparing types.
To Reproduce
from mesa.discrete_space import Cell
from mesa import Model
from mesa.discrete_space import CellAgent
# cell with infinite capacity
cell = Cell((0, 0), capacity=None)
# Add agents
model = Model()
for i in range(100):
agent = CellAgent(model)
agent._mesa_cell = cell
cell._agents.append(agent)
# This does: len(cell.agents) == cell.capacity
# Which is: 100 == None
print(f"is_full: {cell.is_full}")
Additional context Currently works by accident since int == None returns False, but should be fixed for code clarity and type safety. Also changed == to >= in the fix to handle edge cases where agents might exceed capacity.
๐ CodeRabbit Plan Mode
Generate an implementation plan and prompts that you can use with your favorite coding agent.
- [ ] Create Plan
๐ Similar Issues
Related Issues
- https://github.com/mesa/mesa/issues/2962
- https://github.com/mesa/mesa/issues/2968
- https://github.com/mesa/mesa/issues/2811
- https://github.com/mesa/mesa/issues/2958
๐ค Suggested Assignees
๐งช Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
๐ฌ Have feedback or questions? Drop into our discord or schedule a call!
good catch!