Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Ruff to 0.3.4; apply ruff format . #2088

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/WolfSheep/wolf_sheep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions mesa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Core Objects: Model, and Agent.
"""

import datetime

import mesa.space as space
Expand Down
1 change: 1 addition & 0 deletions mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mesa/datacollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions mesa/experimental/cell_space/discrete_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions mesa/experimental/cell_space/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,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
Expand Down
12 changes: 4 additions & 8 deletions mesa/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
1 change: 1 addition & 0 deletions tests/test_datacollector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test the DataCollector
"""

import unittest

from mesa import Agent, Model
Expand Down
1 change: 1 addition & 0 deletions tests/test_grid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test the Grid objects.
"""

import random
import unittest
from unittest.mock import Mock, patch
Expand Down