-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
enhancementRelease notes labelRelease notes label
Description
This issue is split of from feedback on the Mesa 3 JOSS paper.
Summary
Mesa uses type hints in its codebase, which is excellent for documentation and static type checking. However, there are gaps in how agent types are handled, which cause typing errors when running code in a strongly typed environment.
Problems:
model.agentsreturns anAgentSet[Agent]but doesn't maintain the specific agent subclass type information- When accessing
self.modelwithin an agent, the agent doesn't know about the model's specific type - Type checkers can't properly validate attribute access on agents retrieved from collections like
model.agents
Reproducible examples:
Example 1: Type error when accessing agent attributes through model.agents
From the introductory tutorial in "Agents Exchange"/"Running your first model" section:
def step(self):
if self.wealth > 0:
other_agent = self.random.choice(self.model.agents)
other_agent.wealth += 1 # Type error: 'Agent' has no attribute 'wealth'
self.wealth -= 1Example 2: Type error when accessing model attributes from agents
class MyAgent(Agent):
def __init__(self, unique_id, model):
super().__init__(model)
def move(self):
self.model.grid.move_agent(self, new_pos) # Type error: 'Model' has no attribute 'grid'Additional context
This would improve the experience for users working in typed environments or using IDEs with type checking capabilities like PyCharm, VSCode with Pylance, or running mypy on their code.
Metadata
Metadata
Assignees
Labels
enhancementRelease notes labelRelease notes label