From 17a07892310675e3b261088b70f2c4dd1a1461f7 Mon Sep 17 00:00:00 2001 From: rht Date: Sat, 23 Mar 2024 20:08:44 -0400 Subject: [PATCH 1/2] Update Ruff to 0.3.4; apply ruff format . --- .pre-commit-config.yaml | 2 +- benchmarks/WolfSheep/wolf_sheep.py | 3 +-- mesa/__init__.py | 1 + mesa/agent.py | 1 + mesa/datacollection.py | 1 + mesa/experimental/cell_space/discrete_space.py | 3 +-- mesa/experimental/cell_space/grid.py | 6 ++---- mesa/model.py | 1 + mesa/space.py | 12 ++++-------- pyproject.toml | 1 + tests/test_datacollector.py | 1 + tests/test_grid.py | 1 + 12 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32f2f7d53a9..a8467d6f4f1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.2.0 + rev: v0.3.4 hooks: # Run the linter. - id: ruff diff --git a/benchmarks/WolfSheep/wolf_sheep.py b/benchmarks/WolfSheep/wolf_sheep.py index 11e07a9e954..5e1877dbed6 100644 --- a/benchmarks/WolfSheep/wolf_sheep.py +++ b/benchmarks/WolfSheep/wolf_sheep.py @@ -38,8 +38,7 @@ def spawn_offspring(self): offspring.move_to(self.cell) self.model.schedule.add(offspring) - def feed(self): - ... + def feed(self): ... def die(self): self.cell.remove_agent(self) diff --git a/mesa/__init__.py b/mesa/__init__.py index e27d7de1cb0..7bc416a6d29 100644 --- a/mesa/__init__.py +++ b/mesa/__init__.py @@ -3,6 +3,7 @@ Core Objects: Model, and Agent. """ + import datetime import mesa.space as space diff --git a/mesa/agent.py b/mesa/agent.py index 7ae76871b95..ab5e1800138 100644 --- a/mesa/agent.py +++ b/mesa/agent.py @@ -3,6 +3,7 @@ Core Objects: Agent """ + # Mypy; for the `|` operator purpose # Remove this __future__ import once the oldest supported Python is 3.10 from __future__ import annotations diff --git a/mesa/datacollection.py b/mesa/datacollection.py index f5f6ead235b..59247953d82 100644 --- a/mesa/datacollection.py +++ b/mesa/datacollection.py @@ -32,6 +32,7 @@ * The model has an agent list called agents * For collecting agent-level variables, agents must have a unique_id """ + import contextlib import itertools import types diff --git a/mesa/experimental/cell_space/discrete_space.py b/mesa/experimental/cell_space/discrete_space.py index d2161c5b46a..6c92c320cb1 100644 --- a/mesa/experimental/cell_space/discrete_space.py +++ b/mesa/experimental/cell_space/discrete_space.py @@ -43,8 +43,7 @@ def __init__( def cutoff_empties(self): return 7.953 * len(self._cells) ** 0.384 - def _connect_single_cell(self, cell: T): - ... + def _connect_single_cell(self, cell: T): ... @cached_property def all_cells(self): diff --git a/mesa/experimental/cell_space/grid.py b/mesa/experimental/cell_space/grid.py index cc4b4b9e489..e73d18f46fd 100644 --- a/mesa/experimental/cell_space/grid.py +++ b/mesa/experimental/cell_space/grid.py @@ -51,11 +51,9 @@ def _connect_cells(self) -> None: else: self._connect_cells_nd() - def _connect_cells_2d(self) -> None: - ... + def _connect_cells_2d(self) -> None: ... - def _connect_cells_nd(self) -> None: - ... + def _connect_cells_nd(self) -> None: ... def _validate_parameters(self): if not all(isinstance(dim, int) and dim > 0 for dim in self.dimensions): diff --git a/mesa/model.py b/mesa/model.py index be5230dc99b..9b26ed5b12f 100644 --- a/mesa/model.py +++ b/mesa/model.py @@ -3,6 +3,7 @@ Core Objects: Model """ + # Mypy; for the `|` operator purpose # Remove this __future__ import once the oldest supported Python is 3.10 from __future__ import annotations diff --git a/mesa/space.py b/mesa/space.py index 79c570ae89e..b9044387234 100644 --- a/mesa/space.py +++ b/mesa/space.py @@ -150,14 +150,12 @@ def build_empties(self) -> None: self._empties_built = True @overload - def __getitem__(self, index: int | Sequence[Coordinate]) -> list[GridContent]: - ... + def __getitem__(self, index: int | Sequence[Coordinate]) -> list[GridContent]: ... @overload def __getitem__( self, index: tuple[int | slice, int | slice] - ) -> GridContent | list[GridContent]: - ... + ) -> GridContent | list[GridContent]: ... def __getitem__(self, index): """Access contents from the grid.""" @@ -420,11 +418,9 @@ def get_cell_list_contents(self, cell_list: Iterable[Coordinate]) -> list[Agent] """ return list(self.iter_cell_list_contents(cell_list)) - def place_agent(self, agent: Agent, pos: Coordinate) -> None: - ... + def place_agent(self, agent: Agent, pos: Coordinate) -> None: ... - def remove_agent(self, agent: Agent) -> None: - ... + def remove_agent(self, agent: Agent) -> None: ... def move_agent(self, agent: Agent, pos: Coordinate) -> None: """Move an agent from its current position to a new position. diff --git a/pyproject.toml b/pyproject.toml index 4d3d4ad491c..ebc685a0d74 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -132,4 +132,5 @@ extend-ignore = [ "S310", # Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected. "S603", # `subprocess` call: check for execution of untrusted input "ISC001", # ruff format asks to disable this feature + "S311", # Standard pseudo-random generators are not suitable for cryptographic purposes ] diff --git a/tests/test_datacollector.py b/tests/test_datacollector.py index a56ca47745c..bf74e3790d8 100644 --- a/tests/test_datacollector.py +++ b/tests/test_datacollector.py @@ -1,6 +1,7 @@ """ Test the DataCollector """ + import unittest from mesa import Agent, Model diff --git a/tests/test_grid.py b/tests/test_grid.py index b2500bbccb8..be68b1ffe2f 100644 --- a/tests/test_grid.py +++ b/tests/test_grid.py @@ -1,6 +1,7 @@ """ Test the Grid objects. """ + import random import unittest from unittest.mock import Mock, patch From 0ac659881784f295b8186f2aab6e192029c9bd15 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 24 Mar 2024 22:50:30 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mesa/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesa/model.py b/mesa/model.py index 9b26ed5b12f..724fea2ee77 100644 --- a/mesa/model.py +++ b/mesa/model.py @@ -56,7 +56,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Any: if obj._seed is None: # We explicitly specify the seed here so that we know its value in # advance. - obj._seed = random.random() # noqa: S311 + obj._seed = random.random() obj.random = random.Random(obj._seed) # TODO: Remove these 2 lines just before Mesa 3.0 obj._steps = 0