Skip to content

Commit 90628fa

Browse files
committed
Fix ruff error B904
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.
1 parent 8ad831a commit 90628fa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mesa/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def __init__(self, unique_id: int, model: Model) -> None:
5050
# register agent
5151
try:
5252
self.model.agents_[type(self)][self] = None
53-
except AttributeError:
53+
except AttributeError as err:
5454
# model super has not been called
5555
raise RuntimeError(
5656
"The Mesa Model class was not initialized. You must explicitly initialize the Model by calling super().__init__() on initialization."
57-
)
57+
) from err
5858

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

0 commit comments

Comments
 (0)