Enable RUF in ruff

This commit is contained in:
Alexander Hess 2026-11-30 23:17:41 +01:00
commit c56fe649b7
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
9 changed files with 26 additions and 17 deletions

View file

@ -265,6 +265,8 @@ select = [
# "PL", # "PL",
# flake8-use-pathlib => `pathlib` instead of `os` functions # flake8-use-pathlib => `pathlib` instead of `os` functions
# "PTH", # "PTH",
# Ruff-specific rules => Fewer bugs and cleaner code
# "RUF",
# flake8-self => No access to private members from outside # flake8-self => No access to private members from outside
# "SLF", # "SLF",
# pyupgrade => Modern syntax for the targeted Python version # pyupgrade => Modern syntax for the targeted Python version
@ -559,6 +561,8 @@ select = [
"PL", "PL",
# flake8-use-pathlib => `pathlib` instead of `os` functions # flake8-use-pathlib => `pathlib` instead of `os` functions
"PTH", "PTH",
# Ruff-specific rules => Fewer bugs and cleaner code
"RUF",
# flake8-self => No access to private members from outside # flake8-self => No access to private members from outside
"SLF", "SLF",
# flake8-print => no `print()` # flake8-print => no `print()`
@ -576,11 +580,20 @@ extend-ignore = [
"PT023", "PT023",
# An `elif` after a `return` keeps a case distinction together. # An `elif` after a `return` keeps a case distinction together.
"RET505", "RET505",
# Some "# noqa" comments are only for `flake8`, which `ruff` cannot know.
"RUF100",
# TODOs need neither an author nor an issue. # TODOs need neither an author nor an issue.
"TD002", "TD003", "TD002", "TD003",
] ]
# Codes only `flake8` knows, kept in "# noqa" comments
external = [
"B902",
"DOC",
]
[tool.ruff.lint.per-file-ignores] [tool.ruff.lint.per-file-ignores]
# Top-levels of a sub-packages are intended to import a lot. # Top-levels of a sub-packages are intended to import a lot.

View file

@ -40,19 +40,19 @@ class Config:
# Side lengths (in meters) for which pixel grids are created. # Side lengths (in meters) for which pixel grids are created.
# They are the basis for the aggregated demand forecasts. # They are the basis for the aggregated demand forecasts.
GRID_SIDE_LENGTHS = [707, 1000, 1414] GRID_SIDE_LENGTHS = (707, 1000, 1414)
# Time steps (in minutes) used to aggregate the # Time steps (in minutes) used to aggregate the
# individual orders into time series. # individual orders into time series.
TIME_STEPS = [60] TIME_STEPS = (60,)
# Training horizons (in full weeks) used to train the forecasting models. # Training horizons (in full weeks) used to train the forecasting models.
# For now, we only use 7 and 8 weeks as that was the best performing in # For now, we only use 7 and 8 weeks as that was the best performing in
# a previous study (note:4f79e8fa). # a previous study (note:4f79e8fa).
TRAIN_HORIZONS = [7, 8] TRAIN_HORIZONS = (7, 8)
# The demand forecasting methods used in the simulations. # The demand forecasting methods used in the simulations.
FORECASTING_METHODS = ["hets", "rtarima"] FORECASTING_METHODS = ("hets", "rtarima")
# Colors for the visualizations ins `folium`. # Colors for the visualizations ins `folium`.
RESTAURANT_COLOR = "red" RESTAURANT_COLOR = "red"

View file

@ -156,7 +156,7 @@ class Pixel(meta.Base):
"""Shortcut to the `.city.map` object.""" """Shortcut to the `.city.map` object."""
return self.grid.city.map return self.grid.city.map
def draw( # noqa:C901,PLR0912 def draw(
self, self,
*, *,
restaurants: bool = True, restaurants: bool = True,

View file

@ -44,7 +44,7 @@ def test_two_pixels_with_two_addresses(
side_length = max(city.total_x // 2, city.total_y // 2) + 1 side_length = max(city.total_x // 2, city.total_y // 2) + 1
# Hack the configuration regarding the grids to be created. # Hack the configuration regarding the grids to be created.
monkeypatch.setattr(velofy.config, "GRID_SIDE_LENGTHS", [side_length]) monkeypatch.setattr(velofy.config, "GRID_SIDE_LENGTHS", (side_length,))
result = cli.invoke(gridify.gridify) result = cli.invoke(gridify.gridify)

View file

@ -83,9 +83,7 @@ class TestGridification:
all considered `Order.pickup_address` attributes for some orders. all considered `Order.pickup_address` attributes for some orders.
""" """
mock = mocker.Mock() mock = mocker.Mock()
query = ( query = mock.query.return_value.join.return_value.filter.return_value.all
mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501
)
monkeypatch.setattr(db, "session", mock) monkeypatch.setattr(db, "session", mock)
return query return query

View file

@ -1150,7 +1150,7 @@ class TestProperties:
@pytest.mark.db @pytest.mark.db
@pytest.mark.no_cover @pytest.mark.no_cover
def test_make_random_orders( # noqa:C901 def test_make_random_orders(
db_session, db_session,
make_address, make_address,
make_courier, make_courier,

View file

@ -121,9 +121,7 @@ class TestProperties:
def _restaurants_mock(self, mocker, monkeypatch, restaurant): def _restaurants_mock(self, mocker, monkeypatch, restaurant):
"""A `Mock` whose `.return_value` is `[restaurant]`.""" """A `Mock` whose `.return_value` is `[restaurant]`."""
mock = mocker.Mock() mock = mocker.Mock()
query = ( query = mock.query.return_value.join.return_value.filter.return_value.all
mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501
)
query.return_value = [restaurant] query.return_value = [restaurant]
monkeypatch.setattr(db, "session", mock) monkeypatch.setattr(db, "session", mock)

View file

@ -1,5 +1,7 @@
"""Tests for the `velofy.forecasts.models` sub-package.""" """Tests for the `velofy.forecasts.models` sub-package."""
import typing as t
import pandas as pd import pandas as pd
import pytest import pytest
@ -45,7 +47,7 @@ class TestGenericForecastingModelProperties:
assert isinstance(result, str) assert isinstance(result, str)
unique_model_names = set() unique_model_names: t.ClassVar[set[str]] = set()
def test_each_model_has_a_unique_name(self, model_cls, order_history): def test_each_model_has_a_unique_name(self, model_cls, order_history):
"""The `*Model.name` values must be unique across all `*Model`s. """The `*Model.name` values must be unique across all `*Model`s.

View file

@ -26,9 +26,7 @@ class TestAggregateOrders:
Note: This fixture also exists in `tests.db.test_grids`. Note: This fixture also exists in `tests.db.test_grids`.
""" """
mock = mocker.Mock() mock = mocker.Mock()
query = ( query = mock.query.return_value.join.return_value.filter.return_value.all
mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501
)
monkeypatch.setattr(db_session, "query", mock.query) monkeypatch.setattr(db_session, "query", mock.query)
return query return query