Skip to content

Commit

Permalink
Fix last ruff errors
Browse files Browse the repository at this point in the history
-Use with contextlib.suppress(KeyError)
- Supress pickling warning in tests
  • Loading branch information
EwoutH authored and tpike3 committed Dec 23, 2023
1 parent 5fead6b commit 7efc6b6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ def __init__(self, unique_id: int, model: Model) -> None:

def remove(self) -> None:
"""Remove and delete the agent from the model."""
try:
# remove agent
with contextlib.suppress(KeyError):
self.model._agents[type(self)].pop(self)
except KeyError:
pass

def step(self) -> None:
"""A single step of the agent."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_function(agent):
assert agents[0] in agentset

# because AgentSet uses weakrefs, we need hard refs as well....
other_agents, another_set = pickle.loads(
other_agents, another_set = pickle.loads( # noqa: S301
pickle.dumps([agents, AgentSet(agents, model)])
)
assert all(
Expand Down

0 comments on commit 7efc6b6

Please sign in to comment.