Skip to content

Commit

Permalink
Fix ruff error B904
Browse files Browse the repository at this point in the history
Added `from err` to the `raise RuntimeError` line. This links the `RuntimeError` to the original `AttributeError`, making it clear that the new exception was raised because of the `AttributeError` caught in the `try` block.
  • Loading branch information
EwoutH committed Aug 18, 2024
1 parent 8ad831a commit 90628fa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def __init__(self, unique_id: int, model: Model) -> None:
# register agent
try:
self.model.agents_[type(self)][self] = None
except AttributeError:
except AttributeError as err:
# model super has not been called
raise RuntimeError(
"The Mesa Model class was not initialized. You must explicitly initialize the Model by calling super().__init__() on initialization."
)
) from err

def remove(self) -> None:
"""Remove and delete the agent from the model."""
Expand Down

0 comments on commit 90628fa

Please sign in to comment.