From d0d5c92c558022f4329548f7a6caec8ad9c45890 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 20:50:21 +0100 Subject: [PATCH 01/31] Sort the `ruff`-only rule families by code --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index faa2744..5983328 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -481,10 +481,10 @@ select = [ # ======================================= # eradicate => no commented-out code "ERA", - # flake8-import-conventions => Unified import aliases - "ICN", # isort => imports are sorted "I", + # flake8-import-conventions => Unified import aliases + "ICN", # Pylint's refactoring rules => simpler and smaller functions "PLR", # flake8-print => no `print()` -- 2.47.3 From 5dce8e66450c0068fb98830c4fc2733bc6a0abdb Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 20:52:01 +0100 Subject: [PATCH 02/31] Enable UP in `ruff` --- noxfile.py | 2 +- pyproject.toml | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 14897d5..fdbf53d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -520,7 +520,7 @@ def clean_cwd(session: nox.Session) -> None: session.run("rm", "-rf", path) -def _expand(*patterns: str) -> cabc.Generator[pathlib.Path, None, None]: +def _expand(*patterns: str) -> cabc.Generator[pathlib.Path]: """Expand glob patterns into (resolved) paths. Args: diff --git a/pyproject.toml b/pyproject.toml index 5983328..cdfa84d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -231,6 +231,11 @@ select = [ "N8", # pydoclint => docstring matches implementation "DOC", + # ======================================== + # `ruff` only (no working `flake8` plugin) + # ======================================== + # pyupgrade => Modern syntax for the targeted Python version + # "UP", ] # By default, flake8 ignores some errors. @@ -489,6 +494,8 @@ select = [ "PLR", # flake8-print => no `print()` "T20", + # pyupgrade => Modern syntax for the targeted Python version + "UP", ] extend-ignore = [ -- 2.47.3 From 007998372f2d062032b73560892dd791ab713a22 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 20:57:31 +0100 Subject: [PATCH 03/31] Enable SIM in `flake8` and `ruff` --- migrations/env.py | 7 ++----- noxfile.py | 5 ++--- pyproject.toml | 7 +++++++ scripts/get_update_info_for_dependencies.py | 5 +---- src/velofy/db/forecasts.py | 20 ++++---------------- src/velofy/db/pixels.py | 5 +---- src/velofy/forecasts/timify.py | 4 +--- tests/db/utils/test_locations.py | 2 +- uv.lock | 14 ++++++++++++++ 9 files changed, 33 insertions(+), 36 deletions(-) diff --git a/migrations/env.py b/migrations/env.py index 9613a00..19a3c4f 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -21,14 +21,11 @@ log_config.fileConfig(context.config.config_file_name) def include_object(obj, _name, type_, _reflected, _compare_to): """Only include the clean schema into --autogenerate migrations.""" - if ( + return not ( type_ in {"table", "column"} and hasattr(obj, "schema") # => fix for rare edge case and obj.schema != pkg_config.CLEAN_SCHEMA - ): - return False - - return True + ) # Without a `pool`, the `connection` really closes after the migrations diff --git a/noxfile.py b/noxfile.py index fdbf53d..e6a6c2c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -204,6 +204,7 @@ def lint_code(session: nox.Session) -> None: "flake8-pytest-style", "flake8-quotes", "flake8-sfs", + "flake8-simplify", "flake8-todos", "flake8-unused-arguments", "isort", @@ -641,9 +642,7 @@ def skip_install(session: nox.Session) -> bool: # Same logic to skip package installation as in core `nox` # See: https://github.com/wntrblm/nox/blob/2026.10.20/nox/sessions.py#L905 venv = session._runner.venv - if session._runner.global_config.no_install and venv._reused: - return True - return False + return bool(session._runner.global_config.no_install and venv._reused) if MAIN_PYTHON not in SUPPORTED_PYTHONS: diff --git a/pyproject.toml b/pyproject.toml index cdfa84d..5090fe3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -104,6 +104,7 @@ dev = [ "flake8-pytest-style (>=2.2.0,<3.0.0)", "flake8-quotes (>=3.4.0,<4.0.0)", "flake8-sfs (>=1.0.1,<2.0.0)", + "flake8-simplify (>=0.31.1,<0.32.0)", "flake8-todos (>=0.3.1,<0.4.0)", "flake8-unused-arguments (>=0.0.14,<0.1.0)", "mypy (>=2.4.1,<3.0.0)", @@ -223,6 +224,8 @@ select = [ "Q0", # flake8-sfs => use f-strings as the only type of string formatting "SFS", + # flake8-simplify => Simpler code + "SIM", # flake8-todos => unify TODOs "T00", # flake8-unused-arguments => declared function arguments must be used @@ -256,6 +259,8 @@ extend-ignore = [ "PT023", # Allow f-strings as the only type of string formatting. "SFS301", + # `bool()` around a comparison can be deliberate (`ruff` omits this rule). + "SIM901", # TODOs need neither an author nor an issue. "T002", "T003", ] @@ -477,6 +482,8 @@ select = [ "Q", # flake8-bandit => common security issues "S", + # flake8-simplify => Simpler code + "SIM", # flake8-debugger => no debugger usage "T10", # flake8-todos => unify TODOs diff --git a/scripts/get_update_info_for_dependencies.py b/scripts/get_update_info_for_dependencies.py index c9d2010..6ce4c02 100755 --- a/scripts/get_update_info_for_dependencies.py +++ b/scripts/get_update_info_for_dependencies.py @@ -100,10 +100,7 @@ def make_comment( is_latest = pinned_version == latest_version - if is_latest: - comment = "up-to-date" - else: - comment = f"< {latest_version:<8}" + comment = "up-to-date" if is_latest else f"< {latest_version:<8}" if years_since_release > PKG_CONSIDERED_OLD: comment += f" {years_since_release} years ago" diff --git a/src/velofy/db/forecasts.py b/src/velofy/db/forecasts.py index 45717e8..a602f5b 100644 --- a/src/velofy/db/forecasts.py +++ b/src/velofy/db/forecasts.py @@ -232,25 +232,13 @@ class Forecast(meta.Base): low95 = data.loc[timestamp_idx, "low95"] high95 = data.loc[timestamp_idx, "high95"] - if math.isnan(low80): - low80 = None - else: - low80 = float(round(low80, 5)) + low80 = None if math.isnan(low80) else float(round(low80, 5)) - if math.isnan(high80): - high80 = None - else: - high80 = float(round(high80, 5)) + high80 = None if math.isnan(high80) else float(round(high80, 5)) - if math.isnan(low95): - low95 = None - else: - low95 = float(round(low95, 5)) + low95 = None if math.isnan(low95) else float(round(low95, 5)) - if math.isnan(high95): - high95 = None - else: - high95 = float(round(high95, 5)) + high95 = None if math.isnan(high95) else float(round(high95, 5)) forecasts.append( cls( diff --git a/src/velofy/db/pixels.py b/src/velofy/db/pixels.py index 8c1b57b..be6c5c6 100644 --- a/src/velofy/db/pixels.py +++ b/src/velofy/db/pixels.py @@ -177,10 +177,7 @@ class Pixel(meta.Base): info_text = f"Pixel({self.n_x}|{self.n_y})" # Make the `Pixel`s look like a checkerboard. - if (self.n_x + self.n_y) % 2: - color = "#808000" - else: - color = "#ff8c00" + color = "#808000" if (self.n_x + self.n_y) % 2 else "#ff8c00" marker = folium.Rectangle( bounds=bounds, diff --git a/src/velofy/forecasts/timify.py b/src/velofy/forecasts/timify.py index a51ae67..b5700ba 100644 --- a/src/velofy/forecasts/timify.py +++ b/src/velofy/forecasts/timify.py @@ -580,9 +580,7 @@ class OrderHistory: # For now, we only make forecasts with 7 and 8 weeks # as the training horizon (note:4f79e8fa). if train_horizon in {7, 8}: - if add >= 25: # = "high demand" - return models.HorizontalETSModel(order_history=self) - elif add >= 10: # = "medium demand" + if add >= 10: # = "high" or "medium demand" return models.HorizontalETSModel(order_history=self) elif add >= 2.5: # = "low demand" return models.HorizontalSMAModel(order_history=self) diff --git a/tests/db/utils/test_locations.py b/tests/db/utils/test_locations.py index 193ed41..8257652 100644 --- a/tests/db/utils/test_locations.py +++ b/tests/db/utils/test_locations.py @@ -156,7 +156,7 @@ class TestProperties: result = location.zone_details zone, band = result - assert ZONE == f"{zone}{band}" + assert f"{zone}{band}" == ZONE class TestRelateTo: diff --git a/uv.lock b/uv.lock index 636ec4c..a157a60 100644 --- a/uv.lock +++ b/uv.lock @@ -1051,6 +1051,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d1/a8/dc3b3dbe52808d3f09504950d20963a3e19ab1bf6492790b70b8b2e32565/flake8_sfs-1.0.1-py3-none-any.whl", hash = "sha256:ef5f6b3e6d958894fe4c953ecf8e6156d9ab620c7e138f68af5c0f9bfdb4f6b4", size = 6651, upload-time = "2025-09-21T09:31:41.166Z" }, ] +[[package]] +name = "flake8-simplify" +version = "0.31.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "flake8" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/57/3f/484e219a4ecc0242d36135ebe220470633dca035dcea9ce17ad72639db56/flake8_simplify-0.31.1.tar.gz", hash = "sha256:3830f39afed7dc76d6a6f4db006f5a460e1cb8ebe82e08c1d99c5f4e24fab26d", size = 19888, upload-time = "2026-10-06T14:52:31.849Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/11/58/0d4fd5b09de83c42e785b08c21b4bcd3e8f196284293a128037280475e40/flake8_simplify-0.31.1-py3-none-any.whl", hash = "sha256:642c1688a7308e00c6b2b2eb47b0cc66e6ee8440227b8540bab7d05e382279cc", size = 27446, upload-time = "2026-10-06T14:52:30.657Z" }, +] + [[package]] name = "flake8-todos" version = "0.3.1" @@ -3791,6 +3803,7 @@ dev = [ { name = "flake8-pytest-style" }, { name = "flake8-quotes" }, { name = "flake8-sfs" }, + { name = "flake8-simplify" }, { name = "flake8-todos" }, { name = "flake8-unused-arguments" }, { name = "flynt" }, @@ -3857,6 +3870,7 @@ dev = [ { name = "flake8-pytest-style", specifier = ">=2.2.0,<3.0.0" }, { name = "flake8-quotes", specifier = ">=3.4.0,<4.0.0" }, { name = "flake8-sfs", specifier = ">=1.0.1,<2.0.0" }, + { name = "flake8-simplify", specifier = ">=0.31.1,<0.32.0" }, { name = "flake8-todos", specifier = ">=0.3.1,<0.4.0" }, { name = "flake8-unused-arguments", specifier = ">=0.0.14,<0.1.0" }, { name = "flynt", specifier = ">=1.0.6,<2.0.0" }, -- 2.47.3 From 3bd7dd5772d62166321e8734c39fb4ff9b6d55ab Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 21:03:23 +0100 Subject: [PATCH 04/31] Enable RET in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 11 +++++++++++ src/velofy/forecasts/methods/decomposition.py | 5 +---- tests/db/fake_data/fixture_makers.py | 4 +++- uv.lock | 14 ++++++++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/noxfile.py b/noxfile.py index e6a6c2c..5112171 100644 --- a/noxfile.py +++ b/noxfile.py @@ -203,6 +203,7 @@ def lint_code(session: nox.Session) -> None: "flake8-pyproject", "flake8-pytest-style", "flake8-quotes", + "flake8-return", "flake8-sfs", "flake8-simplify", "flake8-todos", diff --git a/pyproject.toml b/pyproject.toml index 5090fe3..5f94dd0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,6 +103,7 @@ dev = [ "flake8-pyproject (>=1.2.4,<2.0.0)", "flake8-pytest-style (>=2.2.0,<3.0.0)", "flake8-quotes (>=3.4.0,<4.0.0)", + "flake8-return (>=1.2.0,<2.0.0)", "flake8-sfs (>=1.0.1,<2.0.0)", "flake8-simplify (>=0.31.1,<0.32.0)", "flake8-todos (>=0.3.1,<0.4.0)", @@ -222,6 +223,8 @@ select = [ "PT0", # flake8-quotes => use double quotes everywhere (complying with black) "Q0", + # flake8-return => Consistent return statements + "R5", # flake8-sfs => use f-strings as the only type of string formatting "SFS", # flake8-simplify => Simpler code @@ -257,6 +260,10 @@ extend-ignore = [ "E203", "W503", # Let's not do `@pytest.mark.no_cover()` instead of `@pytest.mark.no_cover`. "PT023", + # `ruff`'s RET504 does this better, as it allows statements in between. + "R504", + # An `elif` after a `return` keeps a case distinction together. + "R505", # Allow f-strings as the only type of string formatting. "SFS301", # `bool()` around a comparison can be deliberate (`ruff` omits this rule). @@ -480,6 +487,8 @@ select = [ "PT", # flake8-quotes => use double quotes everywhere "Q", + # flake8-return ("R5") => Consistent return statements + "RET", # flake8-bandit => common security issues "S", # flake8-simplify => Simpler code @@ -512,6 +521,8 @@ extend-ignore = [ "PLR2004", # Let's not do `@pytest.mark.no_cover()` instead of `@pytest.mark.no_cover`. "PT023", + # An `elif` after a `return` keeps a case distinction together. + "RET505", # TODOs need neither an author nor an issue. "TD002", "TD003", ] diff --git a/src/velofy/forecasts/methods/decomposition.py b/src/velofy/forecasts/methods/decomposition.py index b77934f..bc84b51 100644 --- a/src/velofy/forecasts/methods/decomposition.py +++ b/src/velofy/forecasts/methods/decomposition.py @@ -149,10 +149,7 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915 if no < 0: raise ValueError("`no` must be non-negative") - elif no > 0: - robust = True - else: - robust = False + robust = no > 0 # Initialize R only if it is actually used. # For example, the nox session "ci-tests-fast" does not use it. diff --git a/tests/db/fake_data/fixture_makers.py b/tests/db/fake_data/fixture_makers.py index 571e506..879f8b1 100644 --- a/tests/db/fake_data/fixture_makers.py +++ b/tests/db/fake_data/fixture_makers.py @@ -142,8 +142,10 @@ def make_replay_order(make_order, simulation): if scheduled: if order and order.ad_hoc is False: raise RuntimeError("`order` must be scheduled") - elif order is None: + + if order is None: order = make_order(scheduled=True) + elif order is None: order = make_order() diff --git a/uv.lock b/uv.lock index a157a60..2ede7be 100644 --- a/uv.lock +++ b/uv.lock @@ -1039,6 +1039,18 @@ dependencies = [ ] sdist = { url = "https://files.pythonhosted.org/packages/dd/57/a173e3eb86072b7ee77650aca496b15d6886367d257f58ea9de5276e330a/flake8-quotes-3.4.0.tar.gz", hash = "sha256:aad8492fb710a2d3eabe68c5f86a1428de650c8484127e14c43d0504ba30276c", size = 14107, upload-time = "2024-02-10T21:58:22.357Z" } +[[package]] +name = "flake8-return" +version = "1.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "flake8-plugin-utils" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/83/49/43ee60c21b61fbec8e86858b2dac7d11a9bdd9958fd7f59077387b6a7197/flake8-return-1.2.0.tar.gz", hash = "sha256:68dfa56582cd704febd02ad86dcf5df67e38e0836d62f1ceae7930d76d3dd955", size = 10033, upload-time = "2022-10-28T09:37:12.507Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f0/8c/6aece77ad2d0d68d8f6e8d5471fd06638de11df656db7d76de810815c437/flake8_return-1.2.0-py3-none-any.whl", hash = "sha256:1f07af12954ed03ebe2c2aac2418f78b55374e9929d4956109664588f31582a1", size = 10121, upload-time = "2022-10-28T09:37:14.468Z" }, +] + [[package]] name = "flake8-sfs" version = "1.0.1" @@ -3802,6 +3814,7 @@ dev = [ { name = "flake8-pyproject" }, { name = "flake8-pytest-style" }, { name = "flake8-quotes" }, + { name = "flake8-return" }, { name = "flake8-sfs" }, { name = "flake8-simplify" }, { name = "flake8-todos" }, @@ -3869,6 +3882,7 @@ dev = [ { name = "flake8-pyproject", specifier = ">=1.2.4,<2.0.0" }, { name = "flake8-pytest-style", specifier = ">=2.2.0,<3.0.0" }, { name = "flake8-quotes", specifier = ">=3.4.0,<4.0.0" }, + { name = "flake8-return", specifier = ">=1.2.0,<2.0.0" }, { name = "flake8-sfs", specifier = ">=1.0.1,<2.0.0" }, { name = "flake8-simplify", specifier = ">=0.31.1,<0.32.0" }, { name = "flake8-todos", specifier = ">=0.3.1,<0.4.0" }, -- 2.47.3 From 0cb924b3b6c1c0e26d9345a2dd7b8c44e43a88b0 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 21:09:05 +0100 Subject: [PATCH 05/31] Enable ISC in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 5 +++++ src/velofy/console/forecasts.py | 6 +++--- src/velofy/forecasts/methods/decomposition.py | 2 +- uv.lock | 11 +++++++++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 5112171..3301b03 100644 --- a/noxfile.py +++ b/noxfile.py @@ -200,6 +200,7 @@ def lint_code(session: nox.Session) -> None: "flake8-comprehensions", "flake8-debugger", "flake8-docstrings", + "flake8-implicit-str-concat", "flake8-pyproject", "flake8-pytest-style", "flake8-quotes", diff --git a/pyproject.toml b/pyproject.toml index 5f94dd0..638927f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -100,6 +100,7 @@ dev = [ "flake8-comprehensions (>=3.17.0,<4.0.0)", "flake8-debugger (>=4.1.2,<5.0.0)", "flake8-docstrings (>=1.7.0,<2.0.0)", + "flake8-implicit-str-concat (>=0.7.0,<0.8.0)", "flake8-pyproject (>=1.2.4,<2.0.0)", "flake8-pytest-style (>=2.2.0,<3.0.0)", "flake8-quotes (>=3.4.0,<4.0.0)", @@ -219,6 +220,8 @@ select = [ "T100", # flake8-docstrings => PEP257 compliance "D1", "D2", "D3", "D4", + # flake8-implicit-str-concat => Unified string concatenation + "ISC", # flake8-pytest-style => enforce a consistent style with pytest "PT0", # flake8-quotes => use double quotes everywhere (complying with black) @@ -481,6 +484,8 @@ select = [ "E", "W", # pyflakes => basic errors "F", + # flake8-implicit-str-concat => Unified string concatenation + "ISC", # pep8-naming => PEP8 naming conventions "N", # flake8-pytest-style => enforce a consistent style with pytest diff --git a/src/velofy/console/forecasts.py b/src/velofy/console/forecasts.py index 0c9f98d..6cfda28 100644 --- a/src/velofy/console/forecasts.py +++ b/src/velofy/console/forecasts.py @@ -90,8 +90,8 @@ def tactical_heuristic( # noqa:C901,D417,DOC001 click.echo( "Parameters: " - + f"city={city}, grid.side_length={side_length}, " - + f"time_step={time_step}, train_horizon={train_horizon}", + f"city={city}, grid.side_length={side_length}, " + f"time_step={time_step}, train_horizon={train_horizon}", ) # Load the historic order data. @@ -132,7 +132,7 @@ def tactical_heuristic( # noqa:C901,D417,DOC001 ) click.echo( f"Predicting pixel #{pixel.id} in {city} " - + f"for {predict_day} with {model.name}", + f"for {predict_day} with {model.name}", ) # Only loop over the time steps corresponding to working hours. diff --git a/src/velofy/forecasts/methods/decomposition.py b/src/velofy/forecasts/methods/decomposition.py index bc84b51..05f4e75 100644 --- a/src/velofy/forecasts/methods/decomposition.py +++ b/src/velofy/forecasts/methods/decomposition.py @@ -104,7 +104,7 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915 if nt % 2 == 0 or nt < default_nt: raise ValueError( "`nt` must be odd and `>= (1.5 * frequency) / [1 - (1.5 / ns)]`, " - + f"which is {default_nt}", + f"which is {default_nt}", ) else: nt = default_nt diff --git a/uv.lock b/uv.lock index 2ede7be..63e606b 100644 --- a/uv.lock +++ b/uv.lock @@ -997,6 +997,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/3f/7d/76a278fa43250441ed9300c344f889c7fb1817080c8fb8996b840bf421c2/flake8_docstrings-1.7.0-py2.py3-none-any.whl", hash = "sha256:51f2344026da083fc084166a9353f5082b01f72901df422f74b4d953ae88ac75", size = 4994, upload-time = "2023-01-25T14:27:12.32Z" }, ] +[[package]] +name = "flake8-implicit-str-concat" +version = "0.7.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/b0/83/cb6050d37bd7bcf01dc81ac20d3db96ffc41aca7f73f81fbf61223d5aa03/flake8_implicit_str_concat-0.7.0.tar.gz", hash = "sha256:492d6d1097ec51ca9e712bef9c5b2e8345867dfa8c744a12bf4ef014fdb18561", size = 9876, upload-time = "2026-07-24T12:15:18.04Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f8/3a/f4906c442afbfea281d7e03322c1761670dca950a4ef4abf1cab218fbc96/flake8_implicit_str_concat-0.7.0-py3-none-any.whl", hash = "sha256:fdabd6c6a314678364053b4a8682495692a43c22f229358e801f711999340d8b", size = 5998, upload-time = "2026-07-24T12:15:16.906Z" }, +] + [[package]] name = "flake8-plugin-utils" version = "1.3.3" @@ -3811,6 +3820,7 @@ dev = [ { name = "flake8-comprehensions" }, { name = "flake8-debugger" }, { name = "flake8-docstrings" }, + { name = "flake8-implicit-str-concat" }, { name = "flake8-pyproject" }, { name = "flake8-pytest-style" }, { name = "flake8-quotes" }, @@ -3879,6 +3889,7 @@ dev = [ { name = "flake8-comprehensions", specifier = ">=3.17.0,<4.0.0" }, { name = "flake8-debugger", specifier = ">=4.1.2,<5.0.0" }, { name = "flake8-docstrings", specifier = ">=1.7.0,<2.0.0" }, + { name = "flake8-implicit-str-concat", specifier = ">=0.7.0,<0.8.0" }, { name = "flake8-pyproject", specifier = ">=1.2.4,<2.0.0" }, { name = "flake8-pytest-style", specifier = ">=2.2.0,<3.0.0" }, { name = "flake8-quotes", specifier = ">=3.4.0,<4.0.0" }, -- 2.47.3 From 9cc21f5b69cbede8bf3fc939147a11b07089bdb9 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 21:11:14 +0100 Subject: [PATCH 06/31] Enable PTH in `ruff` --- noxfile.py | 4 ++-- pyproject.toml | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index 3301b03..9d28d90 100644 --- a/noxfile.py +++ b/noxfile.py @@ -135,7 +135,7 @@ os.environ.setdefault("UV_PYTHON_PREFERENCE", "only-managed") # Where to keep temporary files (e.g., the constraints file in `install_pinned()`) tempfile.tempdir = ".cache/tmp" -os.makedirs(tempfile.tempdir, exist_ok=True) +pathlib.Path(tempfile.tempdir).mkdir(parents=True, exist_ok=True) @nox.session(name="format", python=MAIN_PYTHON) @@ -318,7 +318,7 @@ def build_docs(session: nox.Session) -> None: # Verify that all external links return 200 OK session.run("sphinx-build", "-b", "linkcheck", DOCS_LOCATION, DOCS_BUILD) - session.log(f"Docs are available at {os.getcwd()}/{DOCS_BUILD}index.html") + session.log(f"Docs are available at {pathlib.Path.cwd()}/{DOCS_BUILD}index.html") @nox.session(name="venv", python=MAIN_PYTHON, venv_backend="none") diff --git a/pyproject.toml b/pyproject.toml index 638927f..f033c44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -243,6 +243,8 @@ select = [ # ======================================== # `ruff` only (no working `flake8` plugin) # ======================================== + # flake8-use-pathlib => `pathlib` instead of `os` functions + # "PTH", # pyupgrade => Modern syntax for the targeted Python version # "UP", ] @@ -513,6 +515,8 @@ select = [ "ICN", # Pylint's refactoring rules => simpler and smaller functions "PLR", + # flake8-use-pathlib => `pathlib` instead of `os` functions + "PTH", # flake8-print => no `print()` "T20", # pyupgrade => Modern syntax for the targeted Python version -- 2.47.3 From 0a4fd0edbc2c962b413e5c25634c059c80e0cb2b Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 21:31:38 +0100 Subject: [PATCH 07/31] Enable PERF in `ruff` --- pyproject.toml | 4 ++++ src/velofy/db/utils/colors.py | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f033c44..7d1e232 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -243,6 +243,8 @@ select = [ # ======================================== # `ruff` only (no working `flake8` plugin) # ======================================== + # Perflint => No performance anti-patterns + # "PERF", # flake8-use-pathlib => `pathlib` instead of `os` functions # "PTH", # pyupgrade => Modern syntax for the targeted Python version @@ -513,6 +515,8 @@ select = [ "I", # flake8-import-conventions => Unified import aliases "ICN", + # Perflint => No performance anti-patterns + "PERF", # Pylint's refactoring rules => simpler and smaller functions "PLR", # flake8-use-pathlib => `pathlib` instead of `os` functions diff --git a/src/velofy/db/utils/colors.py b/src/velofy/db/utils/colors.py index 89ba6b3..15e780f 100644 --- a/src/velofy/db/utils/colors.py +++ b/src/velofy/db/utils/colors.py @@ -31,9 +31,7 @@ def make_random_cmap( for _ in range(n_colors) ] - rgb_colors = [] - for color in hsv_colors: - rgb_colors.append(colorsys.hsv_to_rgb(*color)) + rgb_colors = [colorsys.hsv_to_rgb(*color) for color in hsv_colors] else: low = 0.0 -- 2.47.3 From 00aff456c3d5f81067773d38987038e4886f2138 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 21:33:43 +0100 Subject: [PATCH 08/31] Enable FURB in `ruff` --- pyproject.toml | 4 ++++ scripts/get_update_info_for_dependencies.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7d1e232..1fb560b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -243,6 +243,8 @@ select = [ # ======================================== # `ruff` only (no working `flake8` plugin) # ======================================== + # refurb => Modern idioms + # "FURB", # Perflint => No performance anti-patterns # "PERF", # flake8-use-pathlib => `pathlib` instead of `os` functions @@ -511,6 +513,8 @@ select = [ # ======================================= # eradicate => no commented-out code "ERA", + # refurb => Modern idioms + "FURB", # isort => imports are sorted "I", # flake8-import-conventions => Unified import aliases diff --git a/scripts/get_update_info_for_dependencies.py b/scripts/get_update_info_for_dependencies.py index 6ce4c02..9ca926e 100755 --- a/scripts/get_update_info_for_dependencies.py +++ b/scripts/get_update_info_for_dependencies.py @@ -77,7 +77,7 @@ def get_years_since_release( latest_version = data["info"]["version"] release_date = infos_for_pinned_release[0]["upload_time"] - release_date = dt.datetime.fromisoformat(release_date.replace("Z", "+00:00")) + release_date = dt.datetime.fromisoformat(release_date) years_since_release = (dt.datetime.now() - release_date).days / 365.25 -- 2.47.3 From f266adad4575683c90dcf819894c3a7d6ae28a92 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 21:40:43 +0100 Subject: [PATCH 09/31] Enable A in `flake8` and `ruff` --- docs/conf.py | 2 +- noxfile.py | 1 + pyproject.toml | 7 +++++++ uv.lock | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 21bdfdb..674350a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,7 +5,7 @@ import velofy project = velofy.__pkg_name__ author = velofy.__author__ -copyright = f"2020, {author}" +project_copyright = f"2020, {author}" version = release = velofy.__version__ extensions = [ diff --git a/noxfile.py b/noxfile.py index 9d28d90..9b6fdff 100644 --- a/noxfile.py +++ b/noxfile.py @@ -196,6 +196,7 @@ def lint_code(session: nox.Session) -> None: "flake8-black", "flake8-broken-line", "flake8-bugbear", + "flake8-builtins", "flake8-commas", "flake8-comprehensions", "flake8-debugger", diff --git a/pyproject.toml b/pyproject.toml index 1fb560b..9353a20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,6 +96,7 @@ dev = [ "flake8-black (>=0.5.0,<0.6.0)", "flake8-broken-line (>=1.0.0,<2.0.0)", "flake8-bugbear (>=26.11.22,<27.0.0)", + "flake8-builtins (>=3.2.0,<4.0.0)", "flake8-commas (>=4.0.0,<5.0.0)", "flake8-comprehensions (>=3.17.0,<4.0.0)", "flake8-debugger (>=4.1.2,<5.0.0)", @@ -212,6 +213,8 @@ select = [ "N400", # flake8-bugbear => opinionated bugs and design flaws "B0", "B3", "B9", + # flake8-builtins => No shadowing of builtins + "A0", # flake8-commas => better comma placements "C8", # flake8-comprehensions => better comprehensions @@ -260,6 +263,8 @@ ignore = [] # If --ignore is passed on the command # line, still ignore the following: extend-ignore = [ + # `ruff`'s A003 does this better, as it only flags actual shadowing + "A003", # Too long line => duplicate with E501. "B950", # PEP 257 documents the arguments of `__init__()` in its own docstring. @@ -472,6 +477,8 @@ select = [ # =================================== # Violations also covered by `flake8` # =================================== + # flake8-builtins => No shadowing of builtins + "A", # flake8-annotations => enforce type checking for functions "ANN0", "ANN2", # flake8-unused-arguments ("U100") => declared function arguments must be used diff --git a/uv.lock b/uv.lock index 63e606b..3cd83de 100644 --- a/uv.lock +++ b/uv.lock @@ -947,6 +947,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/46/ba/da7d4108baed185aecfc0c8cc8e64b2964f92a1897d3310b79c168ac94d3/flake8_bugbear-26.11.22-py3-none-any.whl", hash = "sha256:bc10d62be1dc512dc7825ee34c20492425370b209e47fb09a1dedd29eba49aca", size = 65763, upload-time = "2026-11-22T14:25:51.217Z" }, ] +[[package]] +name = "flake8-builtins" +version = "3.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "flake8" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/7c/b9/2e42d77e5afe26439eba3df47c9764a4db2d88595531dea587afc3f9b823/flake8_builtins-3.2.0.tar.gz", hash = "sha256:f0c4cee9028711349b7bf18e9a04282a613fd426e56af00bcd0c3bb61ae25481", size = 18444, upload-time = "2026-11-01T10:24:32.991Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b6/02/c7614f54d3fde51b8a20d91e14b012a01c78c2a481d36b5e8e40535a3d0b/flake8_builtins-3.2.0-py3-none-any.whl", hash = "sha256:192a00630f183b8e7b881e98def18aa20124581dde3a3e7be7a01a6effe3504b", size = 18757, upload-time = "2026-11-01T10:24:31.47Z" }, +] + [[package]] name = "flake8-commas" version = "4.0.0" @@ -3816,6 +3828,7 @@ dev = [ { name = "flake8-black" }, { name = "flake8-broken-line" }, { name = "flake8-bugbear" }, + { name = "flake8-builtins" }, { name = "flake8-commas" }, { name = "flake8-comprehensions" }, { name = "flake8-debugger" }, @@ -3885,6 +3898,7 @@ dev = [ { name = "flake8-black", specifier = ">=0.5.0,<0.6.0" }, { name = "flake8-broken-line", specifier = ">=1.0.0,<2.0.0" }, { name = "flake8-bugbear", specifier = ">=26.11.22,<27.0.0" }, + { name = "flake8-builtins", specifier = ">=3.2.0,<4.0.0" }, { name = "flake8-commas", specifier = ">=4.0.0,<5.0.0" }, { name = "flake8-comprehensions", specifier = ">=3.17.0,<4.0.0" }, { name = "flake8-debugger", specifier = ">=4.1.2,<5.0.0" }, -- 2.47.3 From 95f08bc96df9463e1dbc89ac6d221e4f5e7205ba Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 22:11:10 +0100 Subject: [PATCH 10/31] Enable PD in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 7 +++++++ src/velofy/forecasts/methods/arima.py | 2 +- src/velofy/forecasts/methods/decomposition.py | 2 +- src/velofy/forecasts/methods/ets.py | 2 +- .../forecasts/methods/extrapolate_season.py | 4 ++-- .../forecasts/models/tactical/horizontal.py | 8 +++----- src/velofy/forecasts/models/tactical/other.py | 2 +- src/velofy/forecasts/models/tactical/realtime.py | 2 +- src/velofy/forecasts/models/tactical/vertical.py | 2 +- tests/forecasts/test_models.py | 4 ++-- uv.lock | 15 +++++++++++++++ 12 files changed, 36 insertions(+), 15 deletions(-) diff --git a/noxfile.py b/noxfile.py index 9b6fdff..c7227cf 100644 --- a/noxfile.py +++ b/noxfile.py @@ -212,6 +212,7 @@ def lint_code(session: nox.Session) -> None: "flake8-unused-arguments", "isort", "mypy", + "pandas-vet", "pep8-naming", "pydoclint[flake8]", "ruff", diff --git a/pyproject.toml b/pyproject.toml index 9353a20..aa90de3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,6 +111,7 @@ dev = [ "flake8-todos (>=0.3.1,<0.4.0)", "flake8-unused-arguments (>=0.0.14,<0.1.0)", "mypy (>=2.4.1,<3.0.0)", + "pandas-vet (>=2023.8.2)", "pep8-naming (>=0.15.1,<0.16.0)", "pydoclint[flake8] (>=0.12.0,<0.13.0)", "ruff (>=0.17.6,<0.18.0)", @@ -239,6 +240,8 @@ select = [ "T00", # flake8-unused-arguments => declared function arguments must be used "U100", + # pandas-vet => Idiomatic `pandas` + "PD0", # pep8-naming => PEP8 naming conventions "N8", # pydoclint => docstring matches implementation @@ -272,6 +275,8 @@ extend-ignore = [ # Comply with black's style. # Source: https://github.com/psf/black/blob/master/docs/compatible_configs.md#flake8 "E203", "W503", + # Every `.add()` looks like `pandas` to this rule (`ruff` omits it). + "PD005", # Let's not do `@pytest.mark.no_cover()` instead of `@pytest.mark.no_cover`. "PT023", # `ruff`'s RET504 does this better, as it allows statements in between. @@ -501,6 +506,8 @@ select = [ "ISC", # pep8-naming => PEP8 naming conventions "N", + # pandas-vet => Idiomatic `pandas` + "PD", # flake8-pytest-style => enforce a consistent style with pytest "PT", # flake8-quotes => use double quotes everywhere diff --git a/src/velofy/forecasts/methods/arima.py b/src/velofy/forecasts/methods/arima.py index 7aa88f6..4d916ac 100644 --- a/src/velofy/forecasts/methods/arima.py +++ b/src/velofy/forecasts/methods/arima.py @@ -38,7 +38,7 @@ def predict( # Re-seed R every time it is used to ensure reproducibility. robjects.r("set.seed(42)") - if training_ts.isnull().any(): + if training_ts.isna().any(): raise ValueError("`training_ts` must not contain `NaN` values") # Copy the data from Python to R. diff --git a/src/velofy/forecasts/methods/decomposition.py b/src/velofy/forecasts/methods/decomposition.py index 05f4e75..5a0a771 100644 --- a/src/velofy/forecasts/methods/decomposition.py +++ b/src/velofy/forecasts/methods/decomposition.py @@ -93,7 +93,7 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915 """ # Validate all arguments and set default values. - if time_series.isnull().any(): + if time_series.isna().any(): raise ValueError("`time_series` must not contain `NaN` values") if ns % 2 == 0 or ns < 7: diff --git a/src/velofy/forecasts/methods/ets.py b/src/velofy/forecasts/methods/ets.py index 39c443a..ce404bc 100644 --- a/src/velofy/forecasts/methods/ets.py +++ b/src/velofy/forecasts/methods/ets.py @@ -39,7 +39,7 @@ def predict( # Re-seed R every time it is used to ensure reproducibility. robjects.r("set.seed(42)") - if training_ts.isnull().any(): + if training_ts.isna().any(): raise ValueError("`training_ts` must not contain `NaN` values") # Copy the data from Python to R. diff --git a/src/velofy/forecasts/methods/extrapolate_season.py b/src/velofy/forecasts/methods/extrapolate_season.py index 7d70af7..6a5b846 100644 --- a/src/velofy/forecasts/methods/extrapolate_season.py +++ b/src/velofy/forecasts/methods/extrapolate_season.py @@ -36,7 +36,7 @@ def predict( ValueError: if `training_ts` contains `NaN` values or some predictions could not be made for time steps in the `forecast_interval` """ - if training_ts.isnull().any(): + if training_ts.isna().any(): raise ValueError("`training_ts` must not contain `NaN` values") extrapolated_ts = pd.Series(index=forecast_interval, dtype=float) @@ -60,7 +60,7 @@ def predict( idx += seasonal_lag # Sanity check. - if extrapolated_ts.isnull().any(): # pragma: no cover + if extrapolated_ts.isna().any(): # pragma: no cover raise ValueError("missing predictions in the `forecast_interval`") return pd.DataFrame( diff --git a/src/velofy/forecasts/models/tactical/horizontal.py b/src/velofy/forecasts/models/tactical/horizontal.py index 5d461a4..158f60d 100644 --- a/src/velofy/forecasts/models/tactical/horizontal.py +++ b/src/velofy/forecasts/models/tactical/horizontal.py @@ -65,7 +65,7 @@ class HorizontalETSModel(base.ForecastingModelABC): predictions.insert(loc=0, column="actual", value=actuals_ts) # Sanity checks. - if predictions.isnull().sum().any(): # pragma: no cover + if predictions.isna().sum().any(): # pragma: no cover raise RuntimeError("missing predictions in hets model") if predict_at not in predictions.index: # pragma: no cover raise RuntimeError("missing prediction for `predict_at`") @@ -121,7 +121,7 @@ class HorizontalSMAModel(base.ForecastingModelABC): predictions = pd.DataFrame( data={ "actual": actuals_ts, - "prediction": training_ts.values.mean(), + "prediction": training_ts.to_numpy().mean(), "low80": float("NaN"), "high80": float("NaN"), "low95": float("NaN"), @@ -131,9 +131,7 @@ class HorizontalSMAModel(base.ForecastingModelABC): ) # Sanity checks. - if ( - predictions[["actual", "prediction"]].isnull().any().any() - ): # pragma: no cover + if predictions[["actual", "prediction"]].isna().any().any(): # pragma: no cover raise RuntimeError("missing predictions in hsma model") if predict_at not in predictions.index: # pragma: no cover raise RuntimeError("missing prediction for `predict_at`") diff --git a/src/velofy/forecasts/models/tactical/other.py b/src/velofy/forecasts/models/tactical/other.py index f515365..1e617b6 100644 --- a/src/velofy/forecasts/models/tactical/other.py +++ b/src/velofy/forecasts/models/tactical/other.py @@ -73,7 +73,7 @@ class TrivialModel(base.ForecastingModelABC): ) # Sanity checks. - if predictions["actual"].isnull().any(): # pragma: no cover + if predictions["actual"].isna().any(): # pragma: no cover raise RuntimeError("missing actuals in trivial model") if predict_at not in predictions.index: # pragma: no cover raise RuntimeError("missing prediction for `predict_at`") diff --git a/src/velofy/forecasts/models/tactical/realtime.py b/src/velofy/forecasts/models/tactical/realtime.py index e1399e6..c97b75c 100644 --- a/src/velofy/forecasts/models/tactical/realtime.py +++ b/src/velofy/forecasts/models/tactical/realtime.py @@ -115,7 +115,7 @@ class RealtimeARIMAModel(base.ForecastingModelABC): # Sanity checks. if len(predictions) != 1: # pragma: no cover raise RuntimeError("real-time models should predict exactly one time step") - if predictions.isnull().sum().any(): # pragma: no cover + if predictions.isna().sum().any(): # pragma: no cover raise RuntimeError("missing predictions in rtarima model") if predict_at not in predictions.index: # pragma: no cover raise RuntimeError("missing prediction for `predict_at`") diff --git a/src/velofy/forecasts/models/tactical/vertical.py b/src/velofy/forecasts/models/tactical/vertical.py index d41da24..c24c9f4 100644 --- a/src/velofy/forecasts/models/tactical/vertical.py +++ b/src/velofy/forecasts/models/tactical/vertical.py @@ -115,7 +115,7 @@ class VerticalARIMAModel(base.ForecastingModelABC): # Sanity checks. if len(predictions) <= 1: # pragma: no cover raise RuntimeError("vertical models should predict several time steps") - if predictions.isnull().sum().any(): # pragma: no cover + if predictions.isna().sum().any(): # pragma: no cover raise RuntimeError("missing predictions in varima model") if predict_at not in predictions.index: # pragma: no cover raise RuntimeError("missing prediction for `predict_at`") diff --git a/tests/forecasts/test_models.py b/tests/forecasts/test_models.py index f741ba1..30b3f35 100644 --- a/tests/forecasts/test_models.py +++ b/tests/forecasts/test_models.py @@ -131,8 +131,8 @@ class TestGenericForecastingModelProperties: train_horizon=test_config.LONG_TRAIN_HORIZON, ) - assert not result["actual"].isnull().any() - assert not result["prediction"].isnull().any() + assert not result["actual"].isna().any() + assert not result["prediction"].isna().any() @pytest.mark.db @pytest.mark.r diff --git a/uv.lock b/uv.lock index 3cd83de..ead69a0 100644 --- a/uv.lock +++ b/uv.lock @@ -2409,6 +2409,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/08/ab/cce173d73200410f06306a89dbbb5f2125bd64f66ca5eff393d53d813288/pandas-3.1.1-cp315-cp315t-win_arm64.whl", hash = "sha256:4e6f9a3036fc6a40c5ba00efe4092a45844212bdb6a63eda4ad5a5a4c8da45eb", size = 10604158, upload-time = "2026-11-04T15:07:59.733Z" }, ] +[[package]] +name = "pandas-vet" +version = "2023.8.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "attrs" }, + { name = "flake8" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/f5/57/2c8350ff48cece1f6009012a0f42413e9e6d5ca54bec7f3b5726b6e33e1b/pandas_vet-2023.8.2.tar.gz", hash = "sha256:ee6b80b40f5a74de41c29393e4dce373447b363faaa3e0677e4f36799ea865c3", size = 9029, upload-time = "2023-08-11T15:09:03.945Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/17/dd/128ade78c67d4ac1a6202f320112aaa7934eaf8f7b0d861517e7c960dd3f/pandas_vet-2023.8.2-py3-none-any.whl", hash = "sha256:761c07b4479f24fc507465047111c7d21374ec678b7aba58e454fd5d3f8055fe", size = 7396, upload-time = "2023-08-11T15:09:04.842Z" }, +] + [[package]] name = "pandocfilters" version = "1.5.1" @@ -3846,6 +3859,7 @@ dev = [ { name = "isort" }, { name = "mypy" }, { name = "nox" }, + { name = "pandas-vet" }, { name = "pep8-naming" }, { name = "pre-commit" }, { name = "pydoclint", extra = ["flake8"] }, @@ -3916,6 +3930,7 @@ dev = [ { name = "isort", specifier = ">=9.0.2,<10.0.0" }, { name = "mypy", specifier = ">=2.4.1,<3.0.0" }, { name = "nox", specifier = ">=2026.10.20" }, + { name = "pandas-vet", specifier = ">=2023.8.2" }, { name = "pep8-naming", specifier = ">=0.15.1,<0.16.0" }, { name = "pre-commit", specifier = ">=4.7.0,<5.0.0" }, { name = "pydoclint", extras = ["flake8"], specifier = ">=0.12.0,<0.13.0" }, -- 2.47.3 From 99dda74a9ee9128a317c8f831d022f8f7d8aa358 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 22:28:12 +0100 Subject: [PATCH 11/31] Enable PL in `ruff` --- pyproject.toml | 6 ++++-- src/velofy/db/addresses_addresses.py | 4 ++-- src/velofy/db/utils/locations.py | 3 +++ src/velofy/forecasts/methods/arima.py | 2 +- src/velofy/forecasts/methods/decomposition.py | 2 +- src/velofy/forecasts/methods/ets.py | 2 +- tests/test_init_r.py | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index aa90de3..39a2e36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -253,6 +253,8 @@ select = [ # "FURB", # Perflint => No performance anti-patterns # "PERF", + # Pylint => Fewer bugs and simpler code + # "PL", # flake8-use-pathlib => `pathlib` instead of `os` functions # "PTH", # pyupgrade => Modern syntax for the targeted Python version @@ -535,8 +537,8 @@ select = [ "ICN", # Perflint => No performance anti-patterns "PERF", - # Pylint's refactoring rules => simpler and smaller functions - "PLR", + # Pylint => Fewer bugs and simpler code + "PL", # flake8-use-pathlib => `pathlib` instead of `os` functions "PTH", # flake8-print => no `print()` diff --git a/src/velofy/db/addresses_addresses.py b/src/velofy/db/addresses_addresses.py index 1aeb4da..c36e878 100644 --- a/src/velofy/db/addresses_addresses.py +++ b/src/velofy/db/addresses_addresses.py @@ -147,9 +147,9 @@ class Path(meta.Base): paths = [] # We consider all 2-tuples of `Address`es. The symmetric graph is ... - for first, second in itertools.combinations(addresses, 2): + for pair in itertools.combinations(addresses, 2): # ... implicitly enforced by a precedence constraint for the `.id`s. - first, second = (first, second) if first.id < second.id else (second, first) + first, second = sorted(pair, key=lambda address: address.id) # If there is no `Path` object in the database ... path = ( diff --git a/src/velofy/db/utils/locations.py b/src/velofy/db/utils/locations.py index df7ef6b..7ccf31c 100644 --- a/src/velofy/db/utils/locations.py +++ b/src/velofy/db/utils/locations.py @@ -94,6 +94,9 @@ class Location: """The UTM zone of the location as the zone number and the band.""" return self._zone, self._band + # Explicitly unhashable, the default for classes defining only `__eq__()` + __hash__ = None # type: ignore[assignment] + def __eq__(self, other: object) -> bool: """Check if two `Location` objects are the same location.""" if not isinstance(other, Location): diff --git a/src/velofy/forecasts/methods/arima.py b/src/velofy/forecasts/methods/arima.py index 4d916ac..562e3d6 100644 --- a/src/velofy/forecasts/methods/arima.py +++ b/src/velofy/forecasts/methods/arima.py @@ -33,7 +33,7 @@ def predict( """ # Initialize R only if it is actually used. # For example, the nox session "ci-tests-fast" does not use it. - from velofy import init_r # noqa:F401 + from velofy import init_r # noqa:F401,PLC0415 # Re-seed R every time it is used to ensure reproducibility. robjects.r("set.seed(42)") diff --git a/src/velofy/forecasts/methods/decomposition.py b/src/velofy/forecasts/methods/decomposition.py index 5a0a771..ca08ee3 100644 --- a/src/velofy/forecasts/methods/decomposition.py +++ b/src/velofy/forecasts/methods/decomposition.py @@ -153,7 +153,7 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915 # Initialize R only if it is actually used. # For example, the nox session "ci-tests-fast" does not use it. - from velofy import init_r # noqa:F401 + from velofy import init_r # noqa:F401,PLC0415 # Re-seed R every time it is used to ensure reproducibility. robjects.r("set.seed(42)") diff --git a/src/velofy/forecasts/methods/ets.py b/src/velofy/forecasts/methods/ets.py index ce404bc..7098f9d 100644 --- a/src/velofy/forecasts/methods/ets.py +++ b/src/velofy/forecasts/methods/ets.py @@ -34,7 +34,7 @@ def predict( """ # Initialize R only if it is actually used. # For example, the nox session "ci-tests-fast" does not use it. - from velofy import init_r # noqa:F401 + from velofy import init_r # noqa:F401,PLC0415 # Re-seed R every time it is used to ensure reproducibility. robjects.r("set.seed(42)") diff --git a/tests/test_init_r.py b/tests/test_init_r.py index 7a6755a..ef493ab 100644 --- a/tests/test_init_r.py +++ b/tests/test_init_r.py @@ -14,6 +14,6 @@ def test_r_packages_installed(): in the "research/r_dependencies.ipynb" notebook or in the GitHub Actions CI. """ - from velofy import init_r + from velofy import init_r # noqa:PLC0415 assert init_r is not None -- 2.47.3 From d0326aee4f90ba2fa6d19e5c6a006496dd0d5828 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 22:35:24 +0100 Subject: [PATCH 12/31] Enable SLF in `ruff` --- noxfile.py | 7 ++++--- pyproject.toml | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index c7227cf..8c238f4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -557,7 +557,7 @@ def do_not_accept_arguments(session: nox.Session, *, raise_error: bool = True) - def do_not_reuse(session: nox.Session, *, raise_error: bool = True) -> None: """Do not reuse a session with the "-r" or "-R" flags.""" - if session._runner.venv._reused: + if session._runner.venv._reused: # noqa:SLF001 msg = 'be run without the "-r" and "-R" flags' if raise_error: @@ -645,8 +645,9 @@ def skip_install(session: nox.Session) -> bool: """ # Same logic to skip package installation as in core `nox` # See: https://github.com/wntrblm/nox/blob/2026.10.20/nox/sessions.py#L905 - venv = session._runner.venv - return bool(session._runner.global_config.no_install and venv._reused) + no_install = session._runner.global_config.no_install # noqa:SLF001 + venv_reused = session._runner.venv._reused # noqa:SLF001 + return bool(no_install and venv_reused) if MAIN_PYTHON not in SUPPORTED_PYTHONS: diff --git a/pyproject.toml b/pyproject.toml index 39a2e36..a73b259 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -257,6 +257,8 @@ select = [ # "PL", # flake8-use-pathlib => `pathlib` instead of `os` functions # "PTH", + # flake8-self => No access to private members from outside + # "SLF", # pyupgrade => Modern syntax for the targeted Python version # "UP", ] @@ -541,6 +543,8 @@ select = [ "PL", # flake8-use-pathlib => `pathlib` instead of `os` functions "PTH", + # flake8-self => No access to private members from outside + "SLF", # flake8-print => no `print()` "T20", # pyupgrade => Modern syntax for the targeted Python version @@ -579,7 +583,8 @@ extend-ignore = [ # - PLR0913, PLR0917 => `pytest` passes fixtures as arguments. # - S101 => `assert` statements are ok in the test suite. # - S311 => The `random` module is not used for cryptography. -"tests/**/*.py" = ["ANN0", "ANN2", "D106", "PLR0913", "PLR0917", "S101", "S311"] +# - SLF001 => Tests may set up and inspect private members. +"tests/**/*.py" = ["ANN0", "ANN2", "D106", "PLR0913", "PLR0917", "S101", "S311", "SLF001"] [tool.ruff.lint.flake8-pytest-style] # aligned with [tool.flake8] above -- 2.47.3 From 5beb88559fefec6f0dbd99d3c65ad5adaffc1321 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 22:43:35 +0100 Subject: [PATCH 13/31] Enable FBT in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 7 +++++++ src/velofy/console/main.py | 7 ++++++- src/velofy/db/addresses_addresses.py | 2 +- src/velofy/db/cities.py | 1 + src/velofy/db/customers.py | 1 + src/velofy/db/pixels.py | 1 + src/velofy/db/restaurants.py | 1 + src/velofy/db/utils/colors.py | 1 + tests/db/fake_data/fixture_makers.py | 4 ++-- uv.lock | 14 ++++++++++++++ 11 files changed, 36 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 8c238f4..3943923 100644 --- a/noxfile.py +++ b/noxfile.py @@ -194,6 +194,7 @@ def lint_code(session: nox.Session) -> None: "flake8-annotations", "flake8-bandit", "flake8-black", + "flake8-boolean-trap", "flake8-broken-line", "flake8-bugbear", "flake8-builtins", diff --git a/pyproject.toml b/pyproject.toml index a73b259..d649a89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,6 +94,7 @@ dev = [ "flake8-annotations (>=3.3.1,<4.0.0)", "flake8-bandit (>=4.1.1,<5.0.0)", "flake8-black (>=0.5.0,<0.6.0)", + "flake8-boolean-trap (>=1.0.1,<2.0.0)", "flake8-broken-line (>=1.0.0,<2.0.0)", "flake8-bugbear (>=26.11.22,<27.0.0)", "flake8-builtins (>=3.2.0,<4.0.0)", @@ -210,6 +211,8 @@ select = [ "S1", "S2", "S3", "S4", "S5", "S6", "S7", # flake8-black => complain if black would make changes "BLK1", "BLK9", + # flake8-boolean-trap => Keyword-only flags + "FBT", # flake8-broken-line => no \ to end a line "N400", # flake8-bugbear => opinionated bugs and design flaws @@ -279,6 +282,8 @@ extend-ignore = [ # Comply with black's style. # Source: https://github.com/psf/black/blob/master/docs/compatible_configs.md#flake8 "E203", "W503", + # `ruff`'s FBT003 does this better, as it allows builtins like `setattr()`. + "FBT003", # Every `.add()` looks like `pandas` to this rule (`ruff` omits it). "PD005", # Let's not do `@pytest.mark.no_cover()` instead of `@pytest.mark.no_cover`. @@ -506,6 +511,8 @@ select = [ "E", "W", # pyflakes => basic errors "F", + # flake8-boolean-trap => Keyword-only flags + "FBT", # flake8-implicit-str-concat => Unified string concatenation "ISC", # pep8-naming => PEP8 naming conventions diff --git a/src/velofy/console/main.py b/src/velofy/console/main.py index 8446905..0c7dac5 100644 --- a/src/velofy/console/main.py +++ b/src/velofy/console/main.py @@ -8,7 +8,12 @@ from click import core as cli_core import velofy -def show_version(ctx: cli_core.Context, _param: t.Any, value: bool) -> None: +def show_version( + ctx: cli_core.Context, + _param: t.Any, + # `click` passes all arguments to callbacks positionally + value: bool, # noqa:FBT001 +) -> None: """Show the package's version.""" # If --version / -V is NOT passed in, # continue with the command. diff --git a/src/velofy/db/addresses_addresses.py b/src/velofy/db/addresses_addresses.py index c36e878..14cb5c2 100644 --- a/src/velofy/db/addresses_addresses.py +++ b/src/velofy/db/addresses_addresses.py @@ -183,7 +183,7 @@ class Path(meta.Base): return paths @classmethod - def from_order(cls, order: db.Order, google_maps: bool = False) -> Path: + def from_order(cls, order: db.Order, *, google_maps: bool = False) -> Path: """Calculate the path for an `Order` object. The path goes from the `Order.pickup_address` to the `Order.delivery_address`. diff --git a/src/velofy/db/cities.py b/src/velofy/db/cities.py index 258add4..a6fc363 100644 --- a/src/velofy/db/cities.py +++ b/src/velofy/db/cities.py @@ -149,6 +149,7 @@ class City(meta.Base): def draw_restaurants( self, + *, order_counts: bool = False, # pragma: no cover ) -> folium.Map: """Draw all restaurants on the`.map`. diff --git a/src/velofy/db/customers.py b/src/velofy/db/customers.py index b047b24..b7b146c 100644 --- a/src/velofy/db/customers.py +++ b/src/velofy/db/customers.py @@ -46,6 +46,7 @@ class Customer(meta.Base): def draw( # noqa:C901,PLR0912 self, + *, restaurants: bool = True, order_counts: bool = False, # pragma: no cover ) -> folium.Map: diff --git a/src/velofy/db/pixels.py b/src/velofy/db/pixels.py index be6c5c6..981d821 100644 --- a/src/velofy/db/pixels.py +++ b/src/velofy/db/pixels.py @@ -158,6 +158,7 @@ class Pixel(meta.Base): def draw( # noqa:C901,PLR0912 self, + *, restaurants: bool = True, order_counts: bool = False, # pragma: no cover ) -> folium.Map: diff --git a/src/velofy/db/restaurants.py b/src/velofy/db/restaurants.py index bd4c467..73bb101 100644 --- a/src/velofy/db/restaurants.py +++ b/src/velofy/db/restaurants.py @@ -91,6 +91,7 @@ class Restaurant(meta.Base): def draw( self, + *, customers: bool = True, order_counts: bool = False, # pragma: no cover ) -> folium.Map: diff --git a/src/velofy/db/utils/colors.py b/src/velofy/db/utils/colors.py index 15e780f..c7cde67 100644 --- a/src/velofy/db/utils/colors.py +++ b/src/velofy/db/utils/colors.py @@ -8,6 +8,7 @@ from matplotlib import colors def make_random_cmap( n_colors: int, + *, bright: bool = True, # pragma: no cover ) -> colors.LinearSegmentedColormap: """Create a random `Colormap` with `n_colors` different colors. diff --git a/tests/db/fake_data/fixture_makers.py b/tests/db/fake_data/fixture_makers.py index 879f8b1..4cddf82 100644 --- a/tests/db/fake_data/fixture_makers.py +++ b/tests/db/fake_data/fixture_makers.py @@ -77,7 +77,7 @@ def make_order(make_address, make_courier, make_customer, make_restaurant): # Reset the identifiers before every test. factories.AdHocOrderFactory.reset_sequence(1) - def func(scheduled=False, restaurant=None, courier=None, **kwargs): + def func(*, scheduled=False, restaurant=None, courier=None, **kwargs): """Create a new `Order` object. Each `Order` is made by a new `Customer` with a unique `Address` for delivery. @@ -122,7 +122,7 @@ def make_replay_order(make_order, simulation): # Reset the identifiers before every test. factories.ReplayedOrderFactory.reset_sequence(1) - def func(scheduled=False, order=None, **kwargs): + def func(*, scheduled=False, order=None, **kwargs): """Create a new `ReplayedOrder` object. Each `ReplayOrder` is made by a new `Customer` with a unique `Address`. diff --git a/uv.lock b/uv.lock index ead69a0..0ea92f6 100644 --- a/uv.lock +++ b/uv.lock @@ -922,6 +922,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/00/ba/8950a5ef5180c089f5ae474b60555acb0c079bc2b5dd55b7e8193e01be87/flake8_black-0.5.0-py3-none-any.whl", hash = "sha256:28c16f3c5421d1831ce27177926dbaa1d6d460da475afdcd230d409c35495ae7", size = 10167, upload-time = "2026-11-03T11:59:13.491Z" }, ] +[[package]] +name = "flake8-boolean-trap" +version = "1.0.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "flake8" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/df/4f/8ba91d20f54227fa791c4a8e52b9c9b8330f1093da1666de16d4fc8621c7/flake8_boolean_trap-1.0.1.tar.gz", hash = "sha256:603becf640de095fa8ef5e7f8d9945c525ea6913a75df27408be380fd7e0cb3f", size = 4524, upload-time = "2023-07-17T17:01:05.094Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e5/4a/98ecacb66251c8afc8bb9d364995688215f33b451d58be8817b03e4d23b5/flake8_boolean_trap-1.0.1-py3-none-any.whl", hash = "sha256:8c21b1ce2591028750c7a61760df525361b26ef02bf0e8032082dc7fd0d0f377", size = 4430, upload-time = "2023-07-17T17:01:03.636Z" }, +] + [[package]] name = "flake8-broken-line" version = "1.0.0" @@ -3839,6 +3851,7 @@ dev = [ { name = "flake8-annotations" }, { name = "flake8-bandit" }, { name = "flake8-black" }, + { name = "flake8-boolean-trap" }, { name = "flake8-broken-line" }, { name = "flake8-bugbear" }, { name = "flake8-builtins" }, @@ -3910,6 +3923,7 @@ dev = [ { name = "flake8-annotations", specifier = ">=3.3.1,<4.0.0" }, { name = "flake8-bandit", specifier = ">=4.1.1,<5.0.0" }, { name = "flake8-black", specifier = ">=0.5.0,<0.6.0" }, + { name = "flake8-boolean-trap", specifier = ">=1.0.1,<2.0.0" }, { name = "flake8-broken-line", specifier = ">=1.0.0,<2.0.0" }, { name = "flake8-bugbear", specifier = ">=26.11.22,<27.0.0" }, { name = "flake8-builtins", specifier = ">=3.2.0,<4.0.0" }, -- 2.47.3 From 652713e7029f7158076da89e772fe84f51590bcd Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 22:49:41 +0100 Subject: [PATCH 14/31] Enable NPY in `ruff` --- pyproject.toml | 4 ++++ src/velofy/db/utils/colors.py | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d649a89..58186f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -254,6 +254,8 @@ select = [ # ======================================== # refurb => Modern idioms # "FURB", + # NumPy-specific rules => Modern `numpy` APIs + # "NPY", # Perflint => No performance anti-patterns # "PERF", # Pylint => Fewer bugs and simpler code @@ -544,6 +546,8 @@ select = [ "I", # flake8-import-conventions => Unified import aliases "ICN", + # NumPy-specific rules => Modern `numpy` APIs + "NPY", # Perflint => No performance anti-patterns "PERF", # Pylint => Fewer bugs and simpler code diff --git a/src/velofy/db/utils/colors.py b/src/velofy/db/utils/colors.py index c7cde67..c081fe9 100644 --- a/src/velofy/db/utils/colors.py +++ b/src/velofy/db/utils/colors.py @@ -20,14 +20,14 @@ def make_random_cmap( Returns: colormap """ - np.random.seed(42) + rng = np.random.default_rng(42) if bright: hsv_colors = [ ( - np.random.uniform(low=0.0, high=1), - np.random.uniform(low=0.2, high=1), - np.random.uniform(low=0.9, high=1), + rng.uniform(low=0.0, high=1), + rng.uniform(low=0.2, high=1), + rng.uniform(low=0.9, high=1), ) for _ in range(n_colors) ] @@ -40,9 +40,9 @@ def make_random_cmap( rgb_colors = [ ( - np.random.uniform(low=low, high=high), - np.random.uniform(low=low, high=high), - np.random.uniform(low=low, high=high), + rng.uniform(low=low, high=high), + rng.uniform(low=low, high=high), + rng.uniform(low=low, high=high), ) for _ in range(n_colors) ] -- 2.47.3 From ae2dc8db646baa2af819eb5b0d277f86f12032ad Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 22:59:41 +0100 Subject: [PATCH 15/31] Enable EM in `flake8` and `ruff` --- migrations/env.py | 3 +- noxfile.py | 1 + pyproject.toml | 5 ++ src/velofy/configuration.py | 3 +- src/velofy/db/addresses_addresses.py | 3 +- src/velofy/db/orders.py | 81 ++++++++++++------- src/velofy/db/utils/locations.py | 18 +++-- src/velofy/forecasts/methods/arima.py | 3 +- src/velofy/forecasts/methods/decomposition.py | 38 ++++++--- src/velofy/forecasts/methods/ets.py | 3 +- .../forecasts/methods/extrapolate_season.py | 6 +- src/velofy/forecasts/models/base.py | 5 +- .../forecasts/models/tactical/horizontal.py | 23 +++--- src/velofy/forecasts/models/tactical/other.py | 14 ++-- .../forecasts/models/tactical/realtime.py | 9 ++- .../forecasts/models/tactical/vertical.py | 9 ++- src/velofy/forecasts/timify.py | 56 ++++++++----- tests/conftest.py | 6 +- tests/db/fake_data/fixture_makers.py | 3 +- uv.lock | 11 +++ 20 files changed, 201 insertions(+), 99 deletions(-) diff --git a/migrations/env.py b/migrations/env.py index 19a3c4f..e8fc166 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -12,7 +12,8 @@ from velofy import db # Disable the --sql option, a.k.a, the "offline mode". if context.is_offline_mode(): - raise NotImplementedError("The --sql option is not implemented in this project") + msg = "The --sql option is not implemented in this project" + raise NotImplementedError(msg) # Set up the default Python logger from the alembic.ini file. diff --git a/noxfile.py b/noxfile.py index 3943923..60533f4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -202,6 +202,7 @@ def lint_code(session: nox.Session) -> None: "flake8-comprehensions", "flake8-debugger", "flake8-docstrings", + "flake8-errmsg", "flake8-implicit-str-concat", "flake8-pyproject", "flake8-pytest-style", diff --git a/pyproject.toml b/pyproject.toml index 58186f8..d4c2b03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,6 +102,7 @@ dev = [ "flake8-comprehensions (>=3.17.0,<4.0.0)", "flake8-debugger (>=4.1.2,<5.0.0)", "flake8-docstrings (>=1.7.0,<2.0.0)", + "flake8-errmsg (>=0.7.0,<0.8.0)", "flake8-implicit-str-concat (>=0.7.0,<0.8.0)", "flake8-pyproject (>=1.2.4,<2.0.0)", "flake8-pytest-style (>=2.2.0,<3.0.0)", @@ -227,6 +228,8 @@ select = [ "T100", # flake8-docstrings => PEP257 compliance "D1", "D2", "D3", "D4", + # flake8-errmsg => Shorter tracebacks + "EM", # flake8-implicit-str-concat => Unified string concatenation "ISC", # flake8-pytest-style => enforce a consistent style with pytest @@ -511,6 +514,8 @@ select = [ "D", # pycodestyle => PEP8 compliance "E", "W", + # flake8-errmsg => Shorter tracebacks + "EM", # pyflakes => basic errors "F", # flake8-boolean-trap => Keyword-only flags diff --git a/src/velofy/configuration.py b/src/velofy/configuration.py index 6dbdfa9..cc32629 100644 --- a/src/velofy/configuration.py +++ b/src/velofy/configuration.py @@ -115,7 +115,8 @@ def make_config(env: str = "production") -> Config: elif env.strip().lower() == "testing": config = TestingConfig() else: - raise ValueError("Must be either 'production' or 'testing'") + msg = "Must be either 'production' or 'testing'" + raise ValueError(msg) # Without a PostgreSQL database the package cannot work. # As pytest sets the "TESTING" environment variable explicitly, diff --git a/src/velofy/db/addresses_addresses.py b/src/velofy/db/addresses_addresses.py index 14cb5c2..9defe93 100644 --- a/src/velofy/db/addresses_addresses.py +++ b/src/velofy/db/addresses_addresses.py @@ -270,7 +270,8 @@ class Path(meta.Base): underlying attributes (i.e., `._directions`) are to be changed. """ if not self._directions: - raise RuntimeError("_directions is not set") + msg = "_directions is not set" + raise RuntimeError(msg) points = [utils.Location(*point) for point in json.loads(self._directions)] for point in points: diff --git a/src/velofy/db/orders.py b/src/velofy/db/orders.py index 91c66ff..9fb1b07 100644 --- a/src/velofy/db/orders.py +++ b/src/velofy/db/orders.py @@ -549,9 +549,11 @@ class Order(meta.Base): This measures the time it took the UDP to notify the `.courier` after dispatch. """ if not self.dispatch_at: - raise RuntimeError("dispatch_at is not set") + msg = "dispatch_at is not set" + raise RuntimeError(msg) if not self.courier_accepted_at: - raise RuntimeError("courier_accepted_at is not set") + msg = "courier_accepted_at is not set" + raise RuntimeError(msg) return self.courier_accepted_at - self.dispatch_at @property @@ -561,36 +563,44 @@ class Order(meta.Base): A subset of `.time_to_accept`. """ if not self.courier_notified_at: - raise RuntimeError("courier_notified_at is not set") + msg = "courier_notified_at is not set" + raise RuntimeError(msg) if not self.courier_accepted_at: - raise RuntimeError("courier_accepted_at is not set") + msg = "courier_accepted_at is not set" + raise RuntimeError(msg) return self.courier_accepted_at - self.courier_notified_at @property def time_to_pickup(self) -> dt.timedelta: """Time from the `.courier`'s acceptance to arrival at `.pickup_address`.""" if not self.courier_accepted_at: - raise RuntimeError("courier_accepted_at is not set") + msg = "courier_accepted_at is not set" + raise RuntimeError(msg) if not self.reached_pickup_at: - raise RuntimeError("reached_pickup_at is not set") + msg = "reached_pickup_at is not set" + raise RuntimeError(msg) return self.reached_pickup_at - self.courier_accepted_at @property def time_at_pickup(self) -> dt.timedelta: """Time the `.courier` stayed at the `.pickup_address`.""" if not self.reached_pickup_at: - raise RuntimeError("reached_pickup_at is not set") + msg = "reached_pickup_at is not set" + raise RuntimeError(msg) if not self.pickup_at: - raise RuntimeError("pickup_at is not set") + msg = "pickup_at is not set" + raise RuntimeError(msg) return self.pickup_at - self.reached_pickup_at @property def scheduled_pickup_at(self) -> dt.datetime: """Point in time at which the pickup was scheduled.""" if not self.restaurant_notified_at: - raise RuntimeError("restaurant_notified_at is not set") + msg = "restaurant_notified_at is not set" + raise RuntimeError(msg) if not self.estimated_prep_duration: - raise RuntimeError("estimated_prep_duration is not set") + msg = "estimated_prep_duration is not set" + raise RuntimeError(msg) delta = dt.timedelta(seconds=self.estimated_prep_duration) return self.restaurant_notified_at + delta @@ -605,7 +615,8 @@ class Order(meta.Base): Goes together with `.courier_late`. """ if not self.reached_pickup_at: - raise RuntimeError("reached_pickup_at is not set") + msg = "reached_pickup_at is not set" + raise RuntimeError(msg) return max( dt.timedelta(), @@ -623,7 +634,8 @@ class Order(meta.Base): Goes together with `.courier_early`. """ if not self.reached_pickup_at: - raise RuntimeError("reached_pickup_at is not set") + msg = "reached_pickup_at is not set" + raise RuntimeError(msg) return max( dt.timedelta(), @@ -641,7 +653,8 @@ class Order(meta.Base): Goes together with `.restaurant_late`. """ if not self.pickup_at: - raise RuntimeError("pickup_at is not set") + msg = "pickup_at is not set" + raise RuntimeError(msg) return max(dt.timedelta(), self.scheduled_pickup_at - self.pickup_at) @@ -656,7 +669,8 @@ class Order(meta.Base): Goes together with `.restaurant_early`. """ if not self.pickup_at: - raise RuntimeError("pickup_at is not set") + msg = "pickup_at is not set" + raise RuntimeError(msg) return max(dt.timedelta(), self.pickup_at - self.scheduled_pickup_at) @@ -664,18 +678,22 @@ class Order(meta.Base): def time_to_delivery(self) -> dt.timedelta: """Time the `.courier` took from `.pickup_address` to `.delivery_address`.""" if not self.pickup_at: - raise RuntimeError("pickup_at is not set") + msg = "pickup_at is not set" + raise RuntimeError(msg) if not self.reached_delivery_at: - raise RuntimeError("reached_delivery_at is not set") + msg = "reached_delivery_at is not set" + raise RuntimeError(msg) return self.reached_delivery_at - self.pickup_at @property def time_at_delivery(self) -> dt.timedelta: """Time the `.courier` stayed at the `.delivery_address`.""" if not self.reached_delivery_at: - raise RuntimeError("reached_delivery_at is not set") + msg = "reached_delivery_at is not set" + raise RuntimeError(msg) if not self.delivery_at: - raise RuntimeError("delivery_at is not set") + msg = "delivery_at is not set" + raise RuntimeError(msg) return self.delivery_at - self.reached_delivery_at @property @@ -696,11 +714,14 @@ class Order(meta.Base): Goes together with `.delivery_late`. """ if not self.scheduled: - raise AttributeError("Makes sense only for scheduled orders") + msg = "Makes sense only for scheduled orders" + raise AttributeError(msg) if not self.scheduled_delivery_at: - raise RuntimeError("scheduled_delivery_at is not set") + msg = "scheduled_delivery_at is not set" + raise RuntimeError(msg) if not self.delivery_at: - raise RuntimeError("delivery_at is not set") + msg = "delivery_at is not set" + raise RuntimeError(msg) return max(dt.timedelta(), self.scheduled_delivery_at - self.delivery_at) @property @@ -714,22 +735,28 @@ class Order(meta.Base): Goes together with `.delivery_early`. """ if not self.scheduled: - raise AttributeError("Makes sense only for scheduled orders") + msg = "Makes sense only for scheduled orders" + raise AttributeError(msg) if not self.scheduled_delivery_at: - raise RuntimeError("scheduled_delivery_at is not set") + msg = "scheduled_delivery_at is not set" + raise RuntimeError(msg) if not self.delivery_at: - raise RuntimeError("delivery_at is not set") + msg = "delivery_at is not set" + raise RuntimeError(msg) return max(dt.timedelta(), self.delivery_at - self.scheduled_delivery_at) @property def total_time(self) -> dt.timedelta: """Time from order placement to delivery for an `.ad_hoc` order.""" if self.scheduled: - raise AttributeError("Scheduled orders have no total_time") + msg = "Scheduled orders have no total_time" + raise AttributeError(msg) if self.cancelled: - raise RuntimeError("Cancelled orders have no total_time") + msg = "Cancelled orders have no total_time" + raise RuntimeError(msg) if not self.delivery_at: - raise RuntimeError("delivery_at is not set") + msg = "delivery_at is not set" + raise RuntimeError(msg) return self.delivery_at - self.placed_at # Other Methods diff --git a/src/velofy/db/utils/locations.py b/src/velofy/db/utils/locations.py index 7ccf31c..309f57d 100644 --- a/src/velofy/db/utils/locations.py +++ b/src/velofy/db/utils/locations.py @@ -103,7 +103,8 @@ class Location: return NotImplemented if self.zone != other.zone: - raise ValueError("locations must be in the same zone, including the band") + msg = "locations must be in the same zone, including the band" + raise ValueError(msg) return (self.easting, self.northing) == (other.easting, other.northing) @@ -114,7 +115,8 @@ class Location: The origin, which defines the `(0, 0)` coordinate, is set with `.relate_to()`. """ if self._normalized_easting is None: - raise RuntimeError("an origin to relate to must be set first") + msg = "an origin to relate to must be set first" + raise RuntimeError(msg) return self._normalized_easting @@ -125,7 +127,8 @@ class Location: The origin, which defines the `(0, 0)` coordinate, is set with `.relate_to()`. """ if self._normalized_northing is None: - raise RuntimeError("an origin to relate to must be set first") + msg = "an origin to relate to must be set first" + raise RuntimeError(msg) return self._normalized_northing @@ -140,13 +143,16 @@ class Location: properties, the `other` origin may only be set once! """ if self._normalized_easting is not None: - raise RuntimeError("the `other` origin may only be set once") + msg = "the `other` origin may only be set once" + raise RuntimeError(msg) if not isinstance(other, Location): - raise TypeError("`other` is not a `Location` object") + msg = "`other` is not a `Location` object" + raise TypeError(msg) if self.zone != other.zone: - raise ValueError("`other` must be in the same zone, including the band") + msg = "`other` must be in the same zone, including the band" + raise ValueError(msg) self._normalized_easting = self.easting - other.easting self._normalized_northing = self.northing - other.northing diff --git a/src/velofy/forecasts/methods/arima.py b/src/velofy/forecasts/methods/arima.py index 562e3d6..4e62769 100644 --- a/src/velofy/forecasts/methods/arima.py +++ b/src/velofy/forecasts/methods/arima.py @@ -39,7 +39,8 @@ def predict( robjects.r("set.seed(42)") if training_ts.isna().any(): - raise ValueError("`training_ts` must not contain `NaN` values") + msg = "`training_ts` must not contain `NaN` values" + raise ValueError(msg) # Copy the data from Python to R. robjects.globalenv["data"] = robjects.r["ts"]( diff --git a/src/velofy/forecasts/methods/decomposition.py b/src/velofy/forecasts/methods/decomposition.py index ca08ee3..9b884ed 100644 --- a/src/velofy/forecasts/methods/decomposition.py +++ b/src/velofy/forecasts/methods/decomposition.py @@ -94,18 +94,21 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915 # Validate all arguments and set default values. if time_series.isna().any(): - raise ValueError("`time_series` must not contain `NaN` values") + msg = "`time_series` must not contain `NaN` values" + raise ValueError(msg) if ns % 2 == 0 or ns < 7: - raise ValueError("`ns` must be odd and `>= 7`") + msg = "`ns` must be odd and `>= 7`" + raise ValueError(msg) default_nt = math.ceil((1.5 * frequency) / (1 - (1.5 / ns))) if nt is not None: if nt % 2 == 0 or nt < default_nt: - raise ValueError( + msg = ( "`nt` must be odd and `>= (1.5 * frequency) / [1 - (1.5 / ns)]`, " - f"which is {default_nt}", + f"which is {default_nt}" ) + raise ValueError(msg) else: nt = default_nt if nt % 2 == 0: # pragma: no cover => hard to construct edge case @@ -113,42 +116,51 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915 if nl is not None: if nl % 2 == 0 or nl < frequency: - raise ValueError("`nl` must be odd and `>= frequency`") + msg = "`nl` must be odd and `>= frequency`" + raise ValueError(msg) elif frequency % 2 == 0: nl = frequency + 1 else: # pragma: no cover => hard to construct edge case nl = frequency if ds not in {0, 1}: - raise ValueError("`ds` must be either `0` or `1`") + msg = "`ds` must be either `0` or `1`" + raise ValueError(msg) if dt not in {0, 1}: - raise ValueError("`dt` must be either `0` or `1`") + msg = "`dt` must be either `0` or `1`" + raise ValueError(msg) if dl not in {0, 1}: - raise ValueError("`dl` must be either `0` or `1`") + msg = "`dl` must be either `0` or `1`" + raise ValueError(msg) if js is not None: if js <= 0: - raise ValueError("`js` must be positive") + msg = "`js` must be positive" + raise ValueError(msg) else: js = math.ceil(ns / 10) if jt is not None: if jt <= 0: - raise ValueError("`jt` must be positive") + msg = "`jt` must be positive" + raise ValueError(msg) else: jt = math.ceil(nt / 10) if jl is not None: if jl <= 0: - raise ValueError("`jl` must be positive") + msg = "`jl` must be positive" + raise ValueError(msg) else: jl = math.ceil(nl / 10) if ni <= 0: - raise ValueError("`ni` must be positive") + msg = "`ni` must be positive" + raise ValueError(msg) if no < 0: - raise ValueError("`no` must be non-negative") + msg = "`no` must be non-negative" + raise ValueError(msg) robust = no > 0 # Initialize R only if it is actually used. diff --git a/src/velofy/forecasts/methods/ets.py b/src/velofy/forecasts/methods/ets.py index 7098f9d..98ffbf4 100644 --- a/src/velofy/forecasts/methods/ets.py +++ b/src/velofy/forecasts/methods/ets.py @@ -40,7 +40,8 @@ def predict( robjects.r("set.seed(42)") if training_ts.isna().any(): - raise ValueError("`training_ts` must not contain `NaN` values") + msg = "`training_ts` must not contain `NaN` values" + raise ValueError(msg) # Copy the data from Python to R. robjects.globalenv["data"] = robjects.r["ts"]( diff --git a/src/velofy/forecasts/methods/extrapolate_season.py b/src/velofy/forecasts/methods/extrapolate_season.py index 6a5b846..021a413 100644 --- a/src/velofy/forecasts/methods/extrapolate_season.py +++ b/src/velofy/forecasts/methods/extrapolate_season.py @@ -37,7 +37,8 @@ def predict( could not be made for time steps in the `forecast_interval` """ if training_ts.isna().any(): - raise ValueError("`training_ts` must not contain `NaN` values") + msg = "`training_ts` must not contain `NaN` values" + raise ValueError(msg) extrapolated_ts = pd.Series(index=forecast_interval, dtype=float) seasonal_lag = frequency * (training_ts.index[1] - training_ts.index[0]) @@ -61,7 +62,8 @@ def predict( # Sanity check. if extrapolated_ts.isna().any(): # pragma: no cover - raise ValueError("missing predictions in the `forecast_interval`") + msg = "missing predictions in the `forecast_interval`" + raise ValueError(msg) return pd.DataFrame( data={ diff --git a/src/velofy/forecasts/models/base.py b/src/velofy/forecasts/models/base.py index 2b60b85..723172f 100644 --- a/src/velofy/forecasts/models/base.py +++ b/src/velofy/forecasts/models/base.py @@ -118,6 +118,7 @@ class ForecastingModelABC(abc.ABC): return forecast # ..., however, we put in a loud error, just in case. - raise RuntimeError( # pragma: no cover - "`Forecast` for `predict_at` was not returned by `*Model.predict()`", + msg = ( # pragma: no cover + "`Forecast` for `predict_at` was not returned by `*Model.predict()`" ) + raise RuntimeError(msg) # pragma: no cover diff --git a/src/velofy/forecasts/models/tactical/horizontal.py b/src/velofy/forecasts/models/tactical/horizontal.py index 158f60d..4d262d2 100644 --- a/src/velofy/forecasts/models/tactical/horizontal.py +++ b/src/velofy/forecasts/models/tactical/horizontal.py @@ -52,7 +52,8 @@ class HorizontalETSModel(base.ForecastingModelABC): # Sanity check. if frequency != 7: # pragma: no cover - raise RuntimeError("`frequency` should be `7`") + msg = "`frequency` should be `7`" + raise RuntimeError(msg) # Make `predictions` with the seasonal ETS method ("ZZZ" model). predictions = methods.ets.predict( @@ -66,9 +67,11 @@ class HorizontalETSModel(base.ForecastingModelABC): # Sanity checks. if predictions.isna().sum().any(): # pragma: no cover - raise RuntimeError("missing predictions in hets model") + msg = "missing predictions in hets model" + raise RuntimeError(msg) if predict_at not in predictions.index: # pragma: no cover - raise RuntimeError("missing prediction for `predict_at`") + msg = "missing prediction for `predict_at`" + raise RuntimeError(msg) return predictions @@ -109,11 +112,11 @@ class HorizontalSMAModel(base.ForecastingModelABC): # Sanity checks. if frequency != 7: # pragma: no cover - raise RuntimeError("`frequency` should be `7`") + msg = "`frequency` should be `7`" + raise RuntimeError(msg) if len(actuals_ts) != 1: # pragma: no cover - raise RuntimeError( - "the hsma model can only predict one step into the future", - ) + msg = "the hsma model can only predict one step into the future" + raise RuntimeError(msg) # The "prediction" is calculated as the `np.mean()`. # As the `training_ts` covers only full week horizons, @@ -132,8 +135,10 @@ class HorizontalSMAModel(base.ForecastingModelABC): # Sanity checks. if predictions[["actual", "prediction"]].isna().any().any(): # pragma: no cover - raise RuntimeError("missing predictions in hsma model") + msg = "missing predictions in hsma model" + raise RuntimeError(msg) if predict_at not in predictions.index: # pragma: no cover - raise RuntimeError("missing prediction for `predict_at`") + msg = "missing prediction for `predict_at`" + raise RuntimeError(msg) return predictions diff --git a/src/velofy/forecasts/models/tactical/other.py b/src/velofy/forecasts/models/tactical/other.py index 1e617b6..0d0008e 100644 --- a/src/velofy/forecasts/models/tactical/other.py +++ b/src/velofy/forecasts/models/tactical/other.py @@ -53,11 +53,11 @@ class TrivialModel(base.ForecastingModelABC): # Sanity checks. if frequency != 7: # pragma: no cover - raise RuntimeError("`frequency` should be `7`") + msg = "`frequency` should be `7`" + raise RuntimeError(msg) if len(actuals_ts) != 1: # pragma: no cover - raise RuntimeError( - "the trivial model can only predict one step into the future", - ) + msg = "the trivial model can only predict one step into the future" + raise RuntimeError(msg) # The "prediction" is simply `0.0`. predictions = pd.DataFrame( @@ -74,8 +74,10 @@ class TrivialModel(base.ForecastingModelABC): # Sanity checks. if predictions["actual"].isna().any(): # pragma: no cover - raise RuntimeError("missing actuals in trivial model") + msg = "missing actuals in trivial model" + raise RuntimeError(msg) if predict_at not in predictions.index: # pragma: no cover - raise RuntimeError("missing prediction for `predict_at`") + msg = "missing prediction for `predict_at`" + raise RuntimeError(msg) return predictions diff --git a/src/velofy/forecasts/models/tactical/realtime.py b/src/velofy/forecasts/models/tactical/realtime.py index c97b75c..5ef1863 100644 --- a/src/velofy/forecasts/models/tactical/realtime.py +++ b/src/velofy/forecasts/models/tactical/realtime.py @@ -114,10 +114,13 @@ class RealtimeARIMAModel(base.ForecastingModelABC): # Sanity checks. if len(predictions) != 1: # pragma: no cover - raise RuntimeError("real-time models should predict exactly one time step") + msg = "real-time models should predict exactly one time step" + raise RuntimeError(msg) if predictions.isna().sum().any(): # pragma: no cover - raise RuntimeError("missing predictions in rtarima model") + msg = "missing predictions in rtarima model" + raise RuntimeError(msg) if predict_at not in predictions.index: # pragma: no cover - raise RuntimeError("missing prediction for `predict_at`") + msg = "missing prediction for `predict_at`" + raise RuntimeError(msg) return predictions diff --git a/src/velofy/forecasts/models/tactical/vertical.py b/src/velofy/forecasts/models/tactical/vertical.py index c24c9f4..0053fa6 100644 --- a/src/velofy/forecasts/models/tactical/vertical.py +++ b/src/velofy/forecasts/models/tactical/vertical.py @@ -114,10 +114,13 @@ class VerticalARIMAModel(base.ForecastingModelABC): # Sanity checks. if len(predictions) <= 1: # pragma: no cover - raise RuntimeError("vertical models should predict several time steps") + msg = "vertical models should predict several time steps" + raise RuntimeError(msg) if predictions.isna().sum().any(): # pragma: no cover - raise RuntimeError("missing predictions in varima model") + msg = "missing predictions in varima model" + raise RuntimeError(msg) if predict_at not in predictions.index: # pragma: no cover - raise RuntimeError("missing prediction for `predict_at`") + msg = "missing prediction for `predict_at`" + raise RuntimeError(msg) return predictions diff --git a/src/velofy/forecasts/timify.py b/src/velofy/forecasts/timify.py index b5700ba..bc6414a 100644 --- a/src/velofy/forecasts/timify.py +++ b/src/velofy/forecasts/timify.py @@ -37,7 +37,8 @@ class OrderHistory: 60 * (pkg_config.SERVICE_END - pkg_config.SERVICE_START) / time_step ) if n_daily_time_steps != int(n_daily_time_steps): # pragma: no cover - raise RuntimeError("Internal error: configuration has invalid TIME_STEPS") + msg = "Internal error: configuration has invalid TIME_STEPS" + raise RuntimeError(msg) self._n_daily_time_steps = int(n_daily_time_steps) # The `_data` are populated by `.aggregate_orders()`. @@ -193,13 +194,15 @@ class OrderHistory: try: intra_pixel = self.totals.loc[pixel_id] except KeyError: - raise LookupError("The `pixel_id` is not in the `grid`") from None + msg = "The `pixel_id` is not in the `grid`" + raise LookupError(msg) from None first_order = intra_pixel[intra_pixel["n_orders"] > 0].index.min() # Sanity check: without an `Order`, the `Pixel` should not exist. if first_order is pd.NaT: # pragma: no cover - raise RuntimeError("no orders in the pixel") + msg = "no orders in the pixel" + raise RuntimeError(msg) # Return a proper `datetime.datetime` object. return dt.datetime( @@ -226,13 +229,15 @@ class OrderHistory: try: intra_pixel = self.totals.loc[pixel_id] except KeyError: - raise LookupError("The `pixel_id` is not in the `grid`") from None + msg = "The `pixel_id` is not in the `grid`" + raise LookupError(msg) from None last_order = intra_pixel[intra_pixel["n_orders"] > 0].index.max() # Sanity check: without an `Order`, the `Pixel` should not exist. if last_order is pd.NaT: # pragma: no cover - raise RuntimeError("no orders in the pixel") + msg = "no orders in the pixel" + raise RuntimeError(msg) # Return a proper `datetime.datetime` object. return dt.datetime( @@ -273,10 +278,12 @@ class OrderHistory: try: intra_pixel = self.totals.loc[pixel_id] except KeyError: - raise LookupError("The `pixel_id` is not in the `grid`") from None + msg = "The `pixel_id` is not in the `grid`" + raise LookupError(msg) from None if predict_at >= pkg_config.CUTOFF_DAY: # pragma: no cover - raise RuntimeError("Internal error: cannot predict beyond the given data") + msg = "Internal error: cannot predict beyond the given data" + raise RuntimeError(msg) # The first and last training day are just before the `predict_at` day # and span exactly `train_horizon` weeks covering only the times of the @@ -307,11 +314,13 @@ class OrderHistory: "n_orders", ] if len(training_ts) != frequency * train_horizon: - raise RuntimeError("Not enough historic data for `predict_at`") + msg = "Not enough historic data for `predict_at`" + raise RuntimeError(msg) actuals_ts = intra_pixel.loc[[predict_at], "n_orders"] if not len(actuals_ts): # pragma: no cover - raise LookupError("`predict_at` is not in the order history") + msg = "`predict_at` is not in the order history" + raise LookupError(msg) return training_ts, frequency, actuals_ts @@ -345,10 +354,12 @@ class OrderHistory: try: intra_pixel = self.totals.loc[pixel_id] except KeyError: - raise LookupError("The `pixel_id` is not in the `grid`") from None + msg = "The `pixel_id` is not in the `grid`" + raise LookupError(msg) from None if predict_day >= pkg_config.CUTOFF_DAY.date(): # pragma: no cover - raise RuntimeError("Internal error: cannot predict beyond the given data") + msg = "Internal error: cannot predict beyond the given data" + raise RuntimeError(msg) # The first and last training day are just before the `predict_day` # and span exactly `train_horizon` weeks covering all times of the day. @@ -378,7 +389,8 @@ class OrderHistory: "n_orders", ] if len(training_ts) != frequency * train_horizon: - raise RuntimeError("Not enough historic data for `predict_day`") + msg = "Not enough historic data for `predict_day`" + raise RuntimeError(msg) first_prediction_at = dt.datetime( predict_day.year, @@ -400,7 +412,8 @@ class OrderHistory: "n_orders", ] if not len(actuals_ts): # pragma: no cover - raise LookupError("`predict_day` is not in the order history") + msg = "`predict_day` is not in the order history" + raise LookupError(msg) return training_ts, frequency, actuals_ts @@ -434,10 +447,12 @@ class OrderHistory: try: intra_pixel = self.totals.loc[pixel_id] except KeyError: - raise LookupError("The `pixel_id` is not in the `grid`") from None + msg = "The `pixel_id` is not in the `grid`" + raise LookupError(msg) from None if predict_at >= pkg_config.CUTOFF_DAY: # pragma: no cover - raise RuntimeError("Internal error: cannot predict beyond the given data") + msg = "Internal error: cannot predict beyond the given data" + raise RuntimeError(msg) # The first and last training day are just before the `predict_at` day # and span exactly `train_horizon` weeks covering all times of the day, @@ -492,11 +507,13 @@ class OrderHistory: // self._time_step ) if len(training_ts) != frequency * train_horizon + n_time_steps_on_predict_day: - raise RuntimeError("Not enough historic data for `predict_day`") + msg = "Not enough historic data for `predict_day`" + raise RuntimeError(msg) actuals_ts = intra_pixel.loc[[predict_at], "n_orders"] if not len(actuals_ts): # pragma: no cover - raise LookupError("`predict_at` is not in the order history") + msg = "`predict_at` is not in the order history" + raise LookupError(msg) return training_ts, frequency, actuals_ts @@ -588,6 +605,5 @@ class OrderHistory: # = "no demand" return models.TrivialModel(order_history=self) - raise RuntimeError( - "no rule for the given average daily demand and training horizon", - ) + msg = "no rule for the given average daily demand and training horizon" + raise RuntimeError(msg) diff --git a/tests/conftest.py b/tests/conftest.py index bdb2e70..7264128 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,10 +27,12 @@ pytest_plugins = [ # The TESTING environment variable is set # in pyproject.toml in pytest's config section. if not os.getenv("TESTING"): - raise RuntimeError("Tests must be executed with TESTING set in the environment") + msg = "Tests must be executed with TESTING set in the environment" + raise RuntimeError(msg) if not pkg_config.TESTING: - raise RuntimeError("The testing configuration was not loaded") + msg = "The testing configuration was not loaded" + raise RuntimeError(msg) @pytest.fixture(scope="session", params=["all_at_once", "sequentially"]) diff --git a/tests/db/fake_data/fixture_makers.py b/tests/db/fake_data/fixture_makers.py index 4cddf82..d2035f4 100644 --- a/tests/db/fake_data/fixture_makers.py +++ b/tests/db/fake_data/fixture_makers.py @@ -141,7 +141,8 @@ def make_replay_order(make_order, simulation): """ if scheduled: if order and order.ad_hoc is False: - raise RuntimeError("`order` must be scheduled") + msg = "`order` must be scheduled" + raise RuntimeError(msg) if order is None: order = make_order(scheduled=True) diff --git a/uv.lock b/uv.lock index 0ea92f6..a17d31d 100644 --- a/uv.lock +++ b/uv.lock @@ -1021,6 +1021,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/3f/7d/76a278fa43250441ed9300c344f889c7fb1817080c8fb8996b840bf421c2/flake8_docstrings-1.7.0-py2.py3-none-any.whl", hash = "sha256:51f2344026da083fc084166a9353f5082b01f72901df422f74b4d953ae88ac75", size = 4994, upload-time = "2023-01-25T14:27:12.32Z" }, ] +[[package]] +name = "flake8-errmsg" +version = "0.7.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/85/90/be4b2ebfe475a6429dc15fb183abcf9d177dd2320853fca6b5c1b5448812/flake8_errmsg-0.7.0.tar.gz", hash = "sha256:0af7480d4a892c94e7b399ecd38ea4b1889e2c7c8b398080c4c6e756cbacbe95", size = 14557, upload-time = "2026-06-18T14:56:02.366Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/62/47/2d71411967eabc97dc520fc80dc9ea275b07c0357c290e0e8ca1829bc448/flake8_errmsg-0.7.0-py3-none-any.whl", hash = "sha256:406c35d07fc7edc4deb2091e0d9a7177a2102d304f58d56ef18f782834a959f0", size = 9871, upload-time = "2026-06-18T14:56:01.245Z" }, +] + [[package]] name = "flake8-implicit-str-concat" version = "0.7.0" @@ -3859,6 +3868,7 @@ dev = [ { name = "flake8-comprehensions" }, { name = "flake8-debugger" }, { name = "flake8-docstrings" }, + { name = "flake8-errmsg" }, { name = "flake8-implicit-str-concat" }, { name = "flake8-pyproject" }, { name = "flake8-pytest-style" }, @@ -3931,6 +3941,7 @@ dev = [ { name = "flake8-comprehensions", specifier = ">=3.17.0,<4.0.0" }, { name = "flake8-debugger", specifier = ">=4.1.2,<5.0.0" }, { name = "flake8-docstrings", specifier = ">=1.7.0,<2.0.0" }, + { name = "flake8-errmsg", specifier = ">=0.7.0,<0.8.0" }, { name = "flake8-implicit-str-concat", specifier = ">=0.7.0,<0.8.0" }, { name = "flake8-pyproject", specifier = ">=1.2.4,<2.0.0" }, { name = "flake8-pytest-style", specifier = ">=2.2.0,<3.0.0" }, -- 2.47.3 From c56fe649b7c2e898988a87712fe8fc4752089a06 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:17:41 +0100 Subject: [PATCH 16/31] Enable RUF in `ruff` --- pyproject.toml | 13 +++++++++++++ src/velofy/configuration.py | 8 ++++---- src/velofy/db/pixels.py | 2 +- tests/console/test_gridify.py | 2 +- tests/db/test_grids.py | 4 +--- tests/db/test_orders.py | 2 +- tests/db/test_pixels.py | 4 +--- tests/forecasts/test_models.py | 4 +++- tests/forecasts/timify/test_aggregate_orders.py | 4 +--- 9 files changed, 26 insertions(+), 17 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d4c2b03..3a0ce22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -265,6 +265,8 @@ select = [ # "PL", # flake8-use-pathlib => `pathlib` instead of `os` functions # "PTH", + # Ruff-specific rules => Fewer bugs and cleaner code + # "RUF", # flake8-self => No access to private members from outside # "SLF", # pyupgrade => Modern syntax for the targeted Python version @@ -559,6 +561,8 @@ select = [ "PL", # flake8-use-pathlib => `pathlib` instead of `os` functions "PTH", + # Ruff-specific rules => Fewer bugs and cleaner code + "RUF", # flake8-self => No access to private members from outside "SLF", # flake8-print => no `print()` @@ -576,11 +580,20 @@ extend-ignore = [ "PT023", # An `elif` after a `return` keeps a case distinction together. "RET505", + # Some "# noqa" comments are only for `flake8`, which `ruff` cannot know. + "RUF100", # TODOs need neither an author nor an issue. "TD002", "TD003", ] +# Codes only `flake8` knows, kept in "# noqa" comments +external = [ + "B902", + "DOC", +] + + [tool.ruff.lint.per-file-ignores] # Top-levels of a sub-packages are intended to import a lot. diff --git a/src/velofy/configuration.py b/src/velofy/configuration.py index cc32629..1660de8 100644 --- a/src/velofy/configuration.py +++ b/src/velofy/configuration.py @@ -40,19 +40,19 @@ class Config: # Side lengths (in meters) for which pixel grids are created. # 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 # individual orders into time series. - TIME_STEPS = [60] + TIME_STEPS = (60,) # 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 # a previous study (note:4f79e8fa). - TRAIN_HORIZONS = [7, 8] + TRAIN_HORIZONS = (7, 8) # The demand forecasting methods used in the simulations. - FORECASTING_METHODS = ["hets", "rtarima"] + FORECASTING_METHODS = ("hets", "rtarima") # Colors for the visualizations ins `folium`. RESTAURANT_COLOR = "red" diff --git a/src/velofy/db/pixels.py b/src/velofy/db/pixels.py index 981d821..61c5ecf 100644 --- a/src/velofy/db/pixels.py +++ b/src/velofy/db/pixels.py @@ -156,7 +156,7 @@ class Pixel(meta.Base): """Shortcut to the `.city.map` object.""" return self.grid.city.map - def draw( # noqa:C901,PLR0912 + def draw( self, *, restaurants: bool = True, diff --git a/tests/console/test_gridify.py b/tests/console/test_gridify.py index 660edb1..f730951 100644 --- a/tests/console/test_gridify.py +++ b/tests/console/test_gridify.py @@ -44,7 +44,7 @@ def test_two_pixels_with_two_addresses( side_length = max(city.total_x // 2, city.total_y // 2) + 1 # 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) diff --git a/tests/db/test_grids.py b/tests/db/test_grids.py index a0f7e30..9561d43 100644 --- a/tests/db/test_grids.py +++ b/tests/db/test_grids.py @@ -83,9 +83,7 @@ class TestGridification: all considered `Order.pickup_address` attributes for some orders. """ mock = mocker.Mock() - query = ( - mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501 - ) + query = mock.query.return_value.join.return_value.filter.return_value.all monkeypatch.setattr(db, "session", mock) return query diff --git a/tests/db/test_orders.py b/tests/db/test_orders.py index 7ad31f7..3691cdd 100644 --- a/tests/db/test_orders.py +++ b/tests/db/test_orders.py @@ -1150,7 +1150,7 @@ class TestProperties: @pytest.mark.db @pytest.mark.no_cover -def test_make_random_orders( # noqa:C901 +def test_make_random_orders( db_session, make_address, make_courier, diff --git a/tests/db/test_pixels.py b/tests/db/test_pixels.py index bfba927..636328b 100644 --- a/tests/db/test_pixels.py +++ b/tests/db/test_pixels.py @@ -121,9 +121,7 @@ class TestProperties: def _restaurants_mock(self, mocker, monkeypatch, restaurant): """A `Mock` whose `.return_value` is `[restaurant]`.""" mock = mocker.Mock() - query = ( - mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501 - ) + query = mock.query.return_value.join.return_value.filter.return_value.all query.return_value = [restaurant] monkeypatch.setattr(db, "session", mock) diff --git a/tests/forecasts/test_models.py b/tests/forecasts/test_models.py index 30b3f35..ce8173a 100644 --- a/tests/forecasts/test_models.py +++ b/tests/forecasts/test_models.py @@ -1,5 +1,7 @@ """Tests for the `velofy.forecasts.models` sub-package.""" +import typing as t + import pandas as pd import pytest @@ -45,7 +47,7 @@ class TestGenericForecastingModelProperties: 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): """The `*Model.name` values must be unique across all `*Model`s. diff --git a/tests/forecasts/timify/test_aggregate_orders.py b/tests/forecasts/timify/test_aggregate_orders.py index 534aee5..9b625bf 100644 --- a/tests/forecasts/timify/test_aggregate_orders.py +++ b/tests/forecasts/timify/test_aggregate_orders.py @@ -26,9 +26,7 @@ class TestAggregateOrders: Note: This fixture also exists in `tests.db.test_grids`. """ mock = mocker.Mock() - query = ( - mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501 - ) + query = mock.query.return_value.join.return_value.filter.return_value.all monkeypatch.setattr(db_session, "query", mock.query) return query -- 2.47.3 From 0090145b654c098cc464aed757e6c1fdda7487bd Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:27:31 +0100 Subject: [PATCH 17/31] Capitalize the explanations after "=>" --- migrations/env.py | 2 +- pyproject.toml | 64 +++++++++---------- research/02_gridification.ipynb | 6 +- src/velofy/console/forecasts.py | 2 +- src/velofy/console/gridify.py | 2 +- src/velofy/db/orders.py | 2 +- src/velofy/forecasts/methods/decomposition.py | 4 +- .../forecasts/models/tactical/realtime.py | 2 +- .../forecasts/models/tactical/vertical.py | 2 +- tests/db/fake_data/fixture_makers.py | 2 +- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/migrations/env.py b/migrations/env.py index e8fc166..1f95d8c 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -24,7 +24,7 @@ def include_object(obj, _name, type_, _reflected, _compare_to): """Only include the clean schema into --autogenerate migrations.""" return not ( type_ in {"table", "column"} - and hasattr(obj, "schema") # => fix for rare edge case + and hasattr(obj, "schema") # => Fix for rare edge case and obj.schema != pkg_config.CLEAN_SCHEMA ) diff --git a/pyproject.toml b/pyproject.toml index 3a0ce22..a152310 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -197,34 +197,34 @@ select = [ # ============= # flake8's base # ============= - # mccabe => cyclomatic complexity + # mccabe => Cyclomatic complexity "C901", # pycodestyle => PEP8 compliance "E", "W", - # pyflakes => basic errors + # pyflakes => Basic errors "F4", "F5", "F6", "F7", "F8", "F9", # ======= # plugins # ======= - # flake8-annotations => enforce type checking for functions + # flake8-annotations => Enforce type checking for functions "ANN0", "ANN2", "ANN3", - # flake8-bandit => common security issues + # flake8-bandit => Common security issues "S1", "S2", "S3", "S4", "S5", "S6", "S7", - # flake8-black => complain if black would make changes + # flake8-black => Complain if black would make changes "BLK1", "BLK9", # flake8-boolean-trap => Keyword-only flags "FBT", - # flake8-broken-line => no \ to end a line + # flake8-broken-line => No \ to end a line "N400", - # flake8-bugbear => opinionated bugs and design flaws + # flake8-bugbear => Opinionated bugs and design flaws "B0", "B3", "B9", # flake8-builtins => No shadowing of builtins "A0", - # flake8-commas => better comma placements + # flake8-commas => Better comma placements "C8", - # flake8-comprehensions => better comprehensions + # flake8-comprehensions => Better comprehensions "C4", - # flake8-debugger => no debugger usage + # flake8-debugger => No debugger usage "T100", # flake8-docstrings => PEP257 compliance "D1", "D2", "D3", "D4", @@ -232,25 +232,25 @@ select = [ "EM", # flake8-implicit-str-concat => Unified string concatenation "ISC", - # flake8-pytest-style => enforce a consistent style with pytest + # flake8-pytest-style => Enforce a consistent style with pytest "PT0", - # flake8-quotes => use double quotes everywhere (complying with black) + # flake8-quotes => Use double quotes everywhere (complying with black) "Q0", # flake8-return => Consistent return statements "R5", - # flake8-sfs => use f-strings as the only type of string formatting + # flake8-sfs => Use f-strings as the only type of string formatting "SFS", # flake8-simplify => Simpler code "SIM", - # flake8-todos => unify TODOs + # flake8-todos => Unify TODOs "T00", - # flake8-unused-arguments => declared function arguments must be used + # flake8-unused-arguments => Declared function arguments must be used "U100", # pandas-vet => Idiomatic `pandas` "PD0", # pep8-naming => PEP8 naming conventions "N8", - # pydoclint => docstring matches implementation + # pydoclint => Docstring matches implementation "DOC", # ======================================== # `ruff` only (no working `flake8` plugin) @@ -282,7 +282,7 @@ ignore = [] extend-ignore = [ # `ruff`'s A003 does this better, as it only flags actual shadowing "A003", - # Too long line => duplicate with E501. + # Too long line => Duplicate with E501. "B950", # PEP 257 documents the arguments of `__init__()` in its own docstring. "DOC301", @@ -500,17 +500,17 @@ select = [ # =================================== # flake8-builtins => No shadowing of builtins "A", - # flake8-annotations => enforce type checking for functions + # flake8-annotations => Enforce type checking for functions "ANN0", "ANN2", - # flake8-unused-arguments ("U100") => declared function arguments must be used + # flake8-unused-arguments ("U100") => Declared function arguments must be used "ARG", - # flake8-bugbear => opinionated bugs and design flaws + # flake8-bugbear => Opinionated bugs and design flaws "B", - # flake8-comprehensions => better comprehensions + # flake8-comprehensions => Better comprehensions "C4", - # mccabe => cyclomatic complexity + # mccabe => Cyclomatic complexity "C90", - # flake8-commas ("C8") => better comma placements + # flake8-commas ("C8") => Better comma placements "COM", # flake8-docstrings => PEP257 compliance "D", @@ -518,7 +518,7 @@ select = [ "E", "W", # flake8-errmsg => Shorter tracebacks "EM", - # pyflakes => basic errors + # pyflakes => Basic errors "F", # flake8-boolean-trap => Keyword-only flags "FBT", @@ -528,28 +528,28 @@ select = [ "N", # pandas-vet => Idiomatic `pandas` "PD", - # flake8-pytest-style => enforce a consistent style with pytest + # flake8-pytest-style => Enforce a consistent style with pytest "PT", - # flake8-quotes => use double quotes everywhere + # flake8-quotes => Use double quotes everywhere "Q", # flake8-return ("R5") => Consistent return statements "RET", - # flake8-bandit => common security issues + # flake8-bandit => Common security issues "S", # flake8-simplify => Simpler code "SIM", - # flake8-debugger => no debugger usage + # flake8-debugger => No debugger usage "T10", - # flake8-todos => unify TODOs + # flake8-todos => Unify TODOs "TD", # ======================================= # Violations not covered by `flake8` above # ======================================= - # eradicate => no commented-out code + # eradicate => No commented-out code "ERA", # refurb => Modern idioms "FURB", - # isort => imports are sorted + # isort => Imports are sorted "I", # flake8-import-conventions => Unified import aliases "ICN", @@ -565,7 +565,7 @@ select = [ "RUF", # flake8-self => No access to private members from outside "SLF", - # flake8-print => no `print()` + # flake8-print => No `print()` "T20", # pyupgrade => Modern syntax for the targeted Python version "UP", diff --git a/research/02_gridification.ipynb b/research/02_gridification.ipynb index 99e93e7..d2f6a2d 100644 --- a/research/02_gridification.ipynb +++ b/research/02_gridification.ipynb @@ -108,7 +108,7 @@ " -> created 38 pixels\n", "Creating grid with a side length of 1414 meters\n", " -> created 24 pixels\n", - "=> assigned 358 out of 48058 addresses in Lyon\n", + "=> Assigned 358 out of 48058 addresses in Lyon\n", "\n", "Creating grids for Paris\n", "Creating grid with a side length of 707 meters\n", @@ -117,7 +117,7 @@ " -> created 111 pixels\n", "Creating grid with a side length of 1414 meters\n", " -> created 66 pixels\n", - "=> assigned 1133 out of 108135 addresses in Paris\n", + "=> Assigned 1133 out of 108135 addresses in Paris\n", "\n", "Creating grids for Bordeaux\n", "Creating grid with a side length of 707 meters\n", @@ -126,7 +126,7 @@ " -> created 22 pixels\n", "Creating grid with a side length of 1414 meters\n", " -> created 15 pixels\n", - "=> assigned 123 out of 21742 addresses in Bordeaux\n" + "=> Assigned 123 out of 21742 addresses in Bordeaux\n" ] } ], diff --git a/src/velofy/console/forecasts.py b/src/velofy/console/forecasts.py index 6cfda28..e4b3fb6 100644 --- a/src/velofy/console/forecasts.py +++ b/src/velofy/console/forecasts.py @@ -64,7 +64,7 @@ def tactical_heuristic( # noqa:C901,D417,DOC001 TIME_STEP: length of one time step in minutes; defaults to `60` TRAIN_HORIZON: length of the training horizon; defaults to `8` - """ # noqa:D412,D417 => formatted as `click` help text + """ # noqa:D412,D417 => Formatted as `click` help text # Input validation. try: diff --git a/src/velofy/console/gridify.py b/src/velofy/console/gridify.py index 4c82842..9cc0591 100644 --- a/src/velofy/console/gridify.py +++ b/src/velofy/console/gridify.py @@ -42,7 +42,7 @@ def gridify() -> None: # pragma: no cover note:b1f68d24 .count() ) click.echo( - f"=> assigned {n_assigned} out of {len(city.addresses)} addresses in {city.name}", # noqa:E501 + f"=> Assigned {n_assigned} out of {len(city.addresses)} addresses in {city.name}", # noqa:E501 ) db.session.commit() diff --git a/src/velofy/db/orders.py b/src/velofy/db/orders.py index 9fb1b07..00b6cba 100644 --- a/src/velofy/db/orders.py +++ b/src/velofy/db/orders.py @@ -528,7 +528,7 @@ class Order(meta.Base): def corrected(self) -> bool: """If any timestamp was corrected as compared to the original data.""" return bool( - self.scheduled_delivery_at_corrected # => too much logic + self.scheduled_delivery_at_corrected # => Too much logic or self.cancelled_at_corrected or self.restaurant_notified_at_corrected or self.restaurant_confirmed_at_corrected diff --git a/src/velofy/forecasts/methods/decomposition.py b/src/velofy/forecasts/methods/decomposition.py index 9b884ed..85099b0 100644 --- a/src/velofy/forecasts/methods/decomposition.py +++ b/src/velofy/forecasts/methods/decomposition.py @@ -111,7 +111,7 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915 raise ValueError(msg) else: nt = default_nt - if nt % 2 == 0: # pragma: no cover => hard to construct edge case + if nt % 2 == 0: # pragma: no cover => Hard to construct edge case nt += 1 if nl is not None: @@ -120,7 +120,7 @@ def stl( # noqa:C901,PLR0912,PLR0913,PLR0915 raise ValueError(msg) elif frequency % 2 == 0: nl = frequency + 1 - else: # pragma: no cover => hard to construct edge case + else: # pragma: no cover => Hard to construct edge case nl = frequency if ds not in {0, 1}: diff --git a/src/velofy/forecasts/models/tactical/realtime.py b/src/velofy/forecasts/models/tactical/realtime.py index 5ef1863..9d0ce5b 100644 --- a/src/velofy/forecasts/models/tactical/realtime.py +++ b/src/velofy/forecasts/models/tactical/realtime.py @@ -57,7 +57,7 @@ class RealtimeARIMAModel(base.ForecastingModelABC): decomposed_training_ts = methods.decomposition.stl( time_series=training_ts, frequency=frequency, - # "Periodic" `ns` parameter => same seasonal component value + # "Periodic" `ns` parameter => Same seasonal component value # for observations of the same lag. ns=999, ) diff --git a/src/velofy/forecasts/models/tactical/vertical.py b/src/velofy/forecasts/models/tactical/vertical.py index 0053fa6..1a8f10d 100644 --- a/src/velofy/forecasts/models/tactical/vertical.py +++ b/src/velofy/forecasts/models/tactical/vertical.py @@ -57,7 +57,7 @@ class VerticalARIMAModel(base.ForecastingModelABC): decomposed_training_ts = methods.decomposition.stl( time_series=training_ts, frequency=frequency, - # "Periodic" `ns` parameter => same seasonal component value + # "Periodic" `ns` parameter => Same seasonal component value # for observations of the same lag. ns=999, ) diff --git a/tests/db/fake_data/fixture_makers.py b/tests/db/fake_data/fixture_makers.py index d2035f4..0a93683 100644 --- a/tests/db/fake_data/fixture_makers.py +++ b/tests/db/fake_data/fixture_makers.py @@ -105,7 +105,7 @@ def make_order(make_address, make_courier, make_customer, make_restaurant): customer=make_customer(), # assume a unique `Customer` per order courier=courier, pickup_address=restaurant.address, # no `Address` history - delivery_address=make_address(), # unique `Customer` => new `Address` + delivery_address=make_address(), # unique `Customer` => New `Address` **kwargs, ) -- 2.47.3 From ed53324a1d933bcfe07e7c680eb3675a1f718b7e Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:28:04 +0100 Subject: [PATCH 18/31] Hide the capitalization commit from `git blame` --- .git-blame-ignore-revs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 53f16fb..4967ce6 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -54,3 +54,6 @@ de5e49b497cc8f5904637fa5d913e2f8b331f2e8 # Import `velofy.config` as `pkg_config` everywhere cf2534f41e9e535b8f68a38bb3e0ebadf3fb19b3 + +# Capitalize the explanations after "=>" +0090145b654c098cc464aed757e6c1fdda7487bd -- 2.47.3 From 6ebcd69524222afb0f62b9c97c78b891aaaf24a7 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:37:20 +0100 Subject: [PATCH 19/31] Enable BLE in `ruff` --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index a152310..e321a64 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -255,6 +255,8 @@ select = [ # ======================================== # `ruff` only (no working `flake8` plugin) # ======================================== + # flake8-blind-except => No blind `except Exception:` + # "BLE", # refurb => Modern idioms # "FURB", # NumPy-specific rules => Modern `numpy` APIs @@ -545,6 +547,8 @@ select = [ # ======================================= # Violations not covered by `flake8` above # ======================================= + # flake8-blind-except => No blind `except Exception:` + "BLE", # eradicate => No commented-out code "ERA", # refurb => Modern idioms -- 2.47.3 From c32566527ab21d377e1026c00afaf95744518601 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:37:54 +0100 Subject: [PATCH 20/31] Enable EXE in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 5 +++++ uv.lock | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/noxfile.py b/noxfile.py index 60533f4..e18c535 100644 --- a/noxfile.py +++ b/noxfile.py @@ -203,6 +203,7 @@ def lint_code(session: nox.Session) -> None: "flake8-debugger", "flake8-docstrings", "flake8-errmsg", + "flake8-executable", "flake8-implicit-str-concat", "flake8-pyproject", "flake8-pytest-style", diff --git a/pyproject.toml b/pyproject.toml index e321a64..9697100 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,6 +103,7 @@ dev = [ "flake8-debugger (>=4.1.2,<5.0.0)", "flake8-docstrings (>=1.7.0,<2.0.0)", "flake8-errmsg (>=0.7.0,<0.8.0)", + "flake8-executable (>=2.1.3,<3.0.0)", "flake8-implicit-str-concat (>=0.7.0,<0.8.0)", "flake8-pyproject (>=1.2.4,<2.0.0)", "flake8-pytest-style (>=2.2.0,<3.0.0)", @@ -230,6 +231,8 @@ select = [ "D1", "D2", "D3", "D4", # flake8-errmsg => Shorter tracebacks "EM", + # flake8-executable => Consistent shebangs and executable bits + "EXE", # flake8-implicit-str-concat => Unified string concatenation "ISC", # flake8-pytest-style => Enforce a consistent style with pytest @@ -520,6 +523,8 @@ select = [ "E", "W", # flake8-errmsg => Shorter tracebacks "EM", + # flake8-executable => Consistent shebangs and executable bits + "EXE", # pyflakes => Basic errors "F", # flake8-boolean-trap => Keyword-only flags diff --git a/uv.lock b/uv.lock index a17d31d..7b762bb 100644 --- a/uv.lock +++ b/uv.lock @@ -1030,6 +1030,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/62/47/2d71411967eabc97dc520fc80dc9ea275b07c0357c290e0e8ca1829bc448/flake8_errmsg-0.7.0-py3-none-any.whl", hash = "sha256:406c35d07fc7edc4deb2091e0d9a7177a2102d304f58d56ef18f782834a959f0", size = 9871, upload-time = "2026-06-18T14:56:01.245Z" }, ] +[[package]] +name = "flake8-executable" +version = "2.1.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "flake8" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/3b/41/f0687401d76d6031aa5fc447615e1a337308a9c5c586913f70c5a2abe832/flake8-executable-2.1.3.tar.gz", hash = "sha256:619fe023e00c3d8e5113521d7200e1ebb04587c12d157f9a2fb167feb8cae66b", size = 23035, upload-time = "2023-01-23T00:39:57.537Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/bc/d7/311104f82226a6b108f7f05c56cfb7fe773847a879f622d6450ab0a227b3/flake8_executable-2.1.3-py3-none-any.whl", hash = "sha256:f0a66c97c3b99ce63bc1f01ce602d6bd048e4fc5dc0d7a13be2bfa3deb023a34", size = 35302, upload-time = "2023-01-23T00:39:55.485Z" }, +] + [[package]] name = "flake8-implicit-str-concat" version = "0.7.0" @@ -3869,6 +3881,7 @@ dev = [ { name = "flake8-debugger" }, { name = "flake8-docstrings" }, { name = "flake8-errmsg" }, + { name = "flake8-executable" }, { name = "flake8-implicit-str-concat" }, { name = "flake8-pyproject" }, { name = "flake8-pytest-style" }, @@ -3942,6 +3955,7 @@ dev = [ { name = "flake8-debugger", specifier = ">=4.1.2,<5.0.0" }, { name = "flake8-docstrings", specifier = ">=1.7.0,<2.0.0" }, { name = "flake8-errmsg", specifier = ">=0.7.0,<0.8.0" }, + { name = "flake8-executable", specifier = ">=2.1.3,<3.0.0" }, { name = "flake8-implicit-str-concat", specifier = ">=0.7.0,<0.8.0" }, { name = "flake8-pyproject", specifier = ">=1.2.4,<2.0.0" }, { name = "flake8-pytest-style", specifier = ">=2.2.0,<3.0.0" }, -- 2.47.3 From 33daa9cda7b069d436a9437e449c79321e9e9a4c Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:38:13 +0100 Subject: [PATCH 21/31] Enable FLY in `ruff` --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 9697100..6a59b6f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -260,6 +260,8 @@ select = [ # ======================================== # flake8-blind-except => No blind `except Exception:` # "BLE", + # flynt => F-strings instead of `str.join()` + # "FLY", # refurb => Modern idioms # "FURB", # NumPy-specific rules => Modern `numpy` APIs @@ -556,6 +558,8 @@ select = [ "BLE", # eradicate => No commented-out code "ERA", + # flynt => F-strings instead of `str.join()` + "FLY", # refurb => Modern idioms "FURB", # isort => Imports are sorted -- 2.47.3 From 5c62c9919cdf8e93095396e7cc9909be5debf09f Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:38:28 +0100 Subject: [PATCH 22/31] Enable G in `ruff` --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 6a59b6f..1e3e36d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -264,6 +264,8 @@ select = [ # "FLY", # refurb => Modern idioms # "FURB", + # flake8-logging-format => Lazy `logging` messages + # "G", # NumPy-specific rules => Modern `numpy` APIs # "NPY", # Perflint => No performance anti-patterns -- 2.47.3 From d55e72e04d053bb54ac70c4af66c9cb507843d34 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:38:43 +0100 Subject: [PATCH 23/31] Enable LOG in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 5 +++++ uv.lock | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/noxfile.py b/noxfile.py index e18c535..c1c40be 100644 --- a/noxfile.py +++ b/noxfile.py @@ -205,6 +205,7 @@ def lint_code(session: nox.Session) -> None: "flake8-errmsg", "flake8-executable", "flake8-implicit-str-concat", + "flake8-logging", "flake8-pyproject", "flake8-pytest-style", "flake8-quotes", diff --git a/pyproject.toml b/pyproject.toml index 1e3e36d..99402ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,6 +105,7 @@ dev = [ "flake8-errmsg (>=0.7.0,<0.8.0)", "flake8-executable (>=2.1.3,<3.0.0)", "flake8-implicit-str-concat (>=0.7.0,<0.8.0)", + "flake8-logging (>=1.8.0,<2.0.0)", "flake8-pyproject (>=1.2.4,<2.0.0)", "flake8-pytest-style (>=2.2.0,<3.0.0)", "flake8-quotes (>=3.4.0,<4.0.0)", @@ -235,6 +236,8 @@ select = [ "EXE", # flake8-implicit-str-concat => Unified string concatenation "ISC", + # flake8-logging => Correct use of `logging` + "LOG", # flake8-pytest-style => Enforce a consistent style with pytest "PT0", # flake8-quotes => Use double quotes everywhere (complying with black) @@ -535,6 +538,8 @@ select = [ "FBT", # flake8-implicit-str-concat => Unified string concatenation "ISC", + # flake8-logging => Correct use of `logging` + "LOG", # pep8-naming => PEP8 naming conventions "N", # pandas-vet => Idiomatic `pandas` diff --git a/uv.lock b/uv.lock index 7b762bb..f1cdc71 100644 --- a/uv.lock +++ b/uv.lock @@ -1051,6 +1051,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/f8/3a/f4906c442afbfea281d7e03322c1761670dca950a4ef4abf1cab218fbc96/flake8_implicit_str_concat-0.7.0-py3-none-any.whl", hash = "sha256:fdabd6c6a314678364053b4a8682495692a43c22f229358e801f711999340d8b", size = 5998, upload-time = "2026-07-24T12:15:16.906Z" }, ] +[[package]] +name = "flake8-logging" +version = "1.8.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "flake8" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/46/f0/572bd165c171c7a9ac1f82354c11edd09d0b86f35fa914b6db8cf64cce4f/flake8_logging-1.8.0.tar.gz", hash = "sha256:765046763d44d1dc051071c047fe0fa056d71a524505207c3fbdc47532e7d8af", size = 16754, upload-time = "2025-09-08T23:44:44.832Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7d/a3/0192ec49e7fe062130d545f4f6188142ca448b9b63a2622a4ba8ce7e728d/flake8_logging-1.8.0-py3-none-any.whl", hash = "sha256:bb3fcf0fb2b4f35d7ebb0c1dc02af16db00c7c858c5a018370172e939dd6f225", size = 11114, upload-time = "2025-09-08T23:44:43.32Z" }, +] + [[package]] name = "flake8-plugin-utils" version = "1.3.3" @@ -3883,6 +3895,7 @@ dev = [ { name = "flake8-errmsg" }, { name = "flake8-executable" }, { name = "flake8-implicit-str-concat" }, + { name = "flake8-logging" }, { name = "flake8-pyproject" }, { name = "flake8-pytest-style" }, { name = "flake8-quotes" }, @@ -3957,6 +3970,7 @@ dev = [ { name = "flake8-errmsg", specifier = ">=0.7.0,<0.8.0" }, { name = "flake8-executable", specifier = ">=2.1.3,<3.0.0" }, { name = "flake8-implicit-str-concat", specifier = ">=0.7.0,<0.8.0" }, + { name = "flake8-logging", specifier = ">=1.8.0,<2.0.0" }, { name = "flake8-pyproject", specifier = ">=1.2.4,<2.0.0" }, { name = "flake8-pytest-style", specifier = ">=2.2.0,<3.0.0" }, { name = "flake8-quotes", specifier = ">=3.4.0,<4.0.0" }, -- 2.47.3 From 991543046dacfd77d0890aac7115d94b169cdcc1 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:39:08 +0100 Subject: [PATCH 24/31] Enable PGH in `ruff` --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 99402ce..8126fb3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -273,6 +273,8 @@ select = [ # "NPY", # Perflint => No performance anti-patterns # "PERF", + # pygrep-hooks => Specific "# noqa" and "# type: ignore" comments + # "PGH", # Pylint => Fewer bugs and simpler code # "PL", # flake8-use-pathlib => `pathlib` instead of `os` functions @@ -577,6 +579,8 @@ select = [ "NPY", # Perflint => No performance anti-patterns "PERF", + # pygrep-hooks => Specific "# noqa" and "# type: ignore" comments + "PGH", # Pylint => Fewer bugs and simpler code "PL", # flake8-use-pathlib => `pathlib` instead of `os` functions -- 2.47.3 From e612e33f59c08f57d05f326b1c77abc0c82b0716 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:40:15 +0100 Subject: [PATCH 25/31] Enable PIE in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 7 +++++++ src/velofy/forecasts/methods/arima.py | 2 +- src/velofy/forecasts/methods/ets.py | 2 +- uv.lock | 14 ++++++++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index c1c40be..4870e86 100644 --- a/noxfile.py +++ b/noxfile.py @@ -206,6 +206,7 @@ def lint_code(session: nox.Session) -> None: "flake8-executable", "flake8-implicit-str-concat", "flake8-logging", + "flake8-pie", "flake8-pyproject", "flake8-pytest-style", "flake8-quotes", diff --git a/pyproject.toml b/pyproject.toml index 8126fb3..4a23a27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,6 +106,7 @@ dev = [ "flake8-executable (>=2.1.3,<3.0.0)", "flake8-implicit-str-concat (>=0.7.0,<0.8.0)", "flake8-logging (>=1.8.0,<2.0.0)", + "flake8-pie (>=0.16.0,<0.17.0)", "flake8-pyproject (>=1.2.4,<2.0.0)", "flake8-pytest-style (>=2.2.0,<3.0.0)", "flake8-quotes (>=3.4.0,<4.0.0)", @@ -238,6 +239,8 @@ select = [ "ISC", # flake8-logging => Correct use of `logging` "LOG", + # flake8-pie => No unnecessary constructs + "PIE", # flake8-pytest-style => Enforce a consistent style with pytest "PT0", # flake8-quotes => Use double quotes everywhere (complying with black) @@ -307,6 +310,8 @@ extend-ignore = [ "FBT003", # Every `.add()` looks like `pandas` to this rule (`ruff` omits it). "PD005", + # `len()` is needed for `pandas` objects, as their truth value is ambiguous. + "PIE787", # Let's not do `@pytest.mark.no_cover()` instead of `@pytest.mark.no_cover`. "PT023", # `ruff`'s RET504 does this better, as it allows statements in between. @@ -546,6 +551,8 @@ select = [ "N", # pandas-vet => Idiomatic `pandas` "PD", + # flake8-pie => No unnecessary constructs + "PIE", # flake8-pytest-style => Enforce a consistent style with pytest "PT", # flake8-quotes => Use double quotes everywhere diff --git a/src/velofy/forecasts/methods/arima.py b/src/velofy/forecasts/methods/arima.py index 4e62769..9391063 100644 --- a/src/velofy/forecasts/methods/arima.py +++ b/src/velofy/forecasts/methods/arima.py @@ -48,7 +48,7 @@ def predict( frequency=frequency, ) - seasonal = "TRUE" if bool(seasonal_fit) else "FALSE" + seasonal = "TRUE" if seasonal_fit else "FALSE" n_steps_ahead = len(forecast_interval) # Make the predictions in R. diff --git a/src/velofy/forecasts/methods/ets.py b/src/velofy/forecasts/methods/ets.py index 98ffbf4..58a11ad 100644 --- a/src/velofy/forecasts/methods/ets.py +++ b/src/velofy/forecasts/methods/ets.py @@ -49,7 +49,7 @@ def predict( frequency=frequency, ) - model = "ZZZ" if bool(seasonal_fit) else "ZZN" + model = "ZZZ" if seasonal_fit else "ZZN" n_steps_ahead = len(forecast_interval) # Make the predictions in R. diff --git a/uv.lock b/uv.lock index f1cdc71..5ae4aff 100644 --- a/uv.lock +++ b/uv.lock @@ -1063,6 +1063,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/7d/a3/0192ec49e7fe062130d545f4f6188142ca448b9b63a2622a4ba8ce7e728d/flake8_logging-1.8.0-py3-none-any.whl", hash = "sha256:bb3fcf0fb2b4f35d7ebb0c1dc02af16db00c7c858c5a018370172e939dd6f225", size = 11114, upload-time = "2025-09-08T23:44:43.32Z" }, ] +[[package]] +name = "flake8-pie" +version = "0.16.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ae/11/cebfe54fda9897188ca40d1cd755d1be13908ceedfea9e500fae162f06a9/flake8-pie-0.16.0.tar.gz", hash = "sha256:b8dcb7b92706fa33d05d92a4b3e49b7a9fd3f0041849166275b646ba50e515ba", size = 28334, upload-time = "2022-08-08T23:51:12.62Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/83/4c/e953c2402b663155525faba5315df8abe6c02ea7f989cbf43327f5088fc3/flake8_pie-0.16.0-py3-none-any.whl", hash = "sha256:24cd7849b0eee22e2328b9e9d2a1dea40013b0a3106864bbadd06a4b05dbb71f", size = 49171, upload-time = "2022-08-08T23:51:14.535Z" }, +] + [[package]] name = "flake8-plugin-utils" version = "1.3.3" @@ -3896,6 +3908,7 @@ dev = [ { name = "flake8-executable" }, { name = "flake8-implicit-str-concat" }, { name = "flake8-logging" }, + { name = "flake8-pie" }, { name = "flake8-pyproject" }, { name = "flake8-pytest-style" }, { name = "flake8-quotes" }, @@ -3971,6 +3984,7 @@ dev = [ { name = "flake8-executable", specifier = ">=2.1.3,<3.0.0" }, { name = "flake8-implicit-str-concat", specifier = ">=0.7.0,<0.8.0" }, { name = "flake8-logging", specifier = ">=1.8.0,<2.0.0" }, + { name = "flake8-pie", specifier = ">=0.16.0,<0.17.0" }, { name = "flake8-pyproject", specifier = ">=1.2.4,<2.0.0" }, { name = "flake8-pytest-style", specifier = ">=2.2.0,<3.0.0" }, { name = "flake8-quotes", specifier = ">=3.4.0,<4.0.0" }, -- 2.47.3 From 4023f32662be0c59f2410571724a14efaeba367e Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:41:00 +0100 Subject: [PATCH 26/31] Enable RSE in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 5 +++++ uv.lock | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/noxfile.py b/noxfile.py index 4870e86..e61cee3 100644 --- a/noxfile.py +++ b/noxfile.py @@ -210,6 +210,7 @@ def lint_code(session: nox.Session) -> None: "flake8-pyproject", "flake8-pytest-style", "flake8-quotes", + "flake8-raise", "flake8-return", "flake8-sfs", "flake8-simplify", diff --git a/pyproject.toml b/pyproject.toml index 4a23a27..24e1e27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,6 +110,7 @@ dev = [ "flake8-pyproject (>=1.2.4,<2.0.0)", "flake8-pytest-style (>=2.2.0,<3.0.0)", "flake8-quotes (>=3.4.0,<4.0.0)", + "flake8-raise (>=0.0.5,<0.1.0)", "flake8-return (>=1.2.0,<2.0.0)", "flake8-sfs (>=1.0.1,<2.0.0)", "flake8-simplify (>=0.31.1,<0.32.0)", @@ -245,6 +246,8 @@ select = [ "PT0", # flake8-quotes => Use double quotes everywhere (complying with black) "Q0", + # flake8-raise => No parentheses for exceptions without arguments + "R1", # flake8-return => Consistent return statements "R5", # flake8-sfs => Use f-strings as the only type of string formatting @@ -559,6 +562,8 @@ select = [ "Q", # flake8-return ("R5") => Consistent return statements "RET", + # flake8-raise ("R1") => No parentheses for exceptions without arguments + "RSE", # flake8-bandit => Common security issues "S", # flake8-simplify => Simpler code diff --git a/uv.lock b/uv.lock index 5ae4aff..f87ba50 100644 --- a/uv.lock +++ b/uv.lock @@ -1117,6 +1117,18 @@ dependencies = [ ] sdist = { url = "https://files.pythonhosted.org/packages/dd/57/a173e3eb86072b7ee77650aca496b15d6886367d257f58ea9de5276e330a/flake8-quotes-3.4.0.tar.gz", hash = "sha256:aad8492fb710a2d3eabe68c5f86a1428de650c8484127e14c43d0504ba30276c", size = 14107, upload-time = "2024-02-10T21:58:22.357Z" } +[[package]] +name = "flake8-raise" +version = "0.0.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "flake8" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/45/3d/0211d7fb77b3bc6c49495575de4dd07b2ca6fc90a6784bca6097ec980cb9/flake8-raise-0.0.5.tar.gz", hash = "sha256:0a9890e16b851402d9b0d4fafe6c34890eab73835a2c2079c3850a25be575623", size = 5524, upload-time = "2020-01-26T13:53:15.354Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/da/b7/b8edb1ae5c517b8d3cd693129daab16282c5a4b4fc6ad4522cedc29eba61/flake8_raise-0.0.5-py3-none-any.whl", hash = "sha256:df26e5c542a58c8f8786d978e18ad7e54126a0ef5c6241c35dafaca7e2bbb808", size = 3694, upload-time = "2020-01-26T13:53:13.431Z" }, +] + [[package]] name = "flake8-return" version = "1.2.0" @@ -3912,6 +3924,7 @@ dev = [ { name = "flake8-pyproject" }, { name = "flake8-pytest-style" }, { name = "flake8-quotes" }, + { name = "flake8-raise" }, { name = "flake8-return" }, { name = "flake8-sfs" }, { name = "flake8-simplify" }, @@ -3988,6 +4001,7 @@ dev = [ { name = "flake8-pyproject", specifier = ">=1.2.4,<2.0.0" }, { name = "flake8-pytest-style", specifier = ">=2.2.0,<3.0.0" }, { name = "flake8-quotes", specifier = ">=3.4.0,<4.0.0" }, + { name = "flake8-raise", specifier = ">=0.0.5,<0.1.0" }, { name = "flake8-return", specifier = ">=1.2.0,<2.0.0" }, { name = "flake8-sfs", specifier = ">=1.0.1,<2.0.0" }, { name = "flake8-simplify", specifier = ">=0.31.1,<0.32.0" }, -- 2.47.3 From 1827e02f3473769e09cc095dc453f3fc911f9643 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:41:42 +0100 Subject: [PATCH 27/31] Enable TID in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 5 +++++ uv.lock | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/noxfile.py b/noxfile.py index e61cee3..b083310 100644 --- a/noxfile.py +++ b/noxfile.py @@ -214,6 +214,7 @@ def lint_code(session: nox.Session) -> None: "flake8-return", "flake8-sfs", "flake8-simplify", + "flake8-tidy-imports", "flake8-todos", "flake8-unused-arguments", "isort", diff --git a/pyproject.toml b/pyproject.toml index 24e1e27..958b5f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -114,6 +114,7 @@ dev = [ "flake8-return (>=1.2.0,<2.0.0)", "flake8-sfs (>=1.0.1,<2.0.0)", "flake8-simplify (>=0.31.1,<0.32.0)", + "flake8-tidy-imports (>=4.12.0,<5.0.0)", "flake8-todos (>=0.3.1,<0.4.0)", "flake8-unused-arguments (>=0.0.14,<0.1.0)", "mypy (>=2.4.1,<3.0.0)", @@ -254,6 +255,8 @@ select = [ "SFS", # flake8-simplify => Simpler code "SIM", + # flake8-tidy-imports => No relative imports + "I25", # flake8-todos => Unify TODOs "T00", # flake8-unused-arguments => Declared function arguments must be used @@ -572,6 +575,8 @@ select = [ "T10", # flake8-todos => Unify TODOs "TD", + # flake8-tidy-imports ("I25") => No relative imports + "TID", # ======================================= # Violations not covered by `flake8` above # ======================================= diff --git a/uv.lock b/uv.lock index f87ba50..31d18b5 100644 --- a/uv.lock +++ b/uv.lock @@ -1165,6 +1165,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/11/58/0d4fd5b09de83c42e785b08c21b4bcd3e8f196284293a128037280475e40/flake8_simplify-0.31.1-py3-none-any.whl", hash = "sha256:642c1688a7308e00c6b2b2eb47b0cc66e6ee8440227b8540bab7d05e382279cc", size = 27446, upload-time = "2026-10-06T14:52:30.657Z" }, ] +[[package]] +name = "flake8-tidy-imports" +version = "4.12.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "flake8" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/4d/24/ce374a8028f3f3d2c48082693d5b4a2b7073e6be64579ecff20bcefdb812/flake8_tidy_imports-4.12.0.tar.gz", hash = "sha256:9254788c3b6862c2fcec0250d2dc9af089afebff9c5b8a8ac8b9525b059b06db", size = 13946, upload-time = "2025-09-08T23:44:06.651Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/93/16/bc792adda2b19d501f474bbf6eb0b35546db01f4816459153bd69a388d03/flake8_tidy_imports-4.12.0-py3-none-any.whl", hash = "sha256:ab1e31a5ce07518a31c0a34cd92551f4c27639ae2c35a21364680a0318da312e", size = 10034, upload-time = "2025-09-08T23:44:05.535Z" }, +] + [[package]] name = "flake8-todos" version = "0.3.1" @@ -3928,6 +3940,7 @@ dev = [ { name = "flake8-return" }, { name = "flake8-sfs" }, { name = "flake8-simplify" }, + { name = "flake8-tidy-imports" }, { name = "flake8-todos" }, { name = "flake8-unused-arguments" }, { name = "flynt" }, @@ -4005,6 +4018,7 @@ dev = [ { name = "flake8-return", specifier = ">=1.2.0,<2.0.0" }, { name = "flake8-sfs", specifier = ">=1.0.1,<2.0.0" }, { name = "flake8-simplify", specifier = ">=0.31.1,<0.32.0" }, + { name = "flake8-tidy-imports", specifier = ">=4.12.0,<5.0.0" }, { name = "flake8-todos", specifier = ">=0.3.1,<0.4.0" }, { name = "flake8-unused-arguments", specifier = ">=0.0.14,<0.1.0" }, { name = "flynt", specifier = ">=1.0.6,<2.0.0" }, -- 2.47.3 From 57ac60261299446627052d471eb77f9893b5d7a4 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:42:08 +0100 Subject: [PATCH 28/31] Enable TRY in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 9 +++++++++ uv.lock | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/noxfile.py b/noxfile.py index b083310..b1924fc 100644 --- a/noxfile.py +++ b/noxfile.py @@ -223,6 +223,7 @@ def lint_code(session: nox.Session) -> None: "pep8-naming", "pydoclint[flake8]", "ruff", + "tryceratops", ) # Interpret extra arguments as `locations` of source files diff --git a/pyproject.toml b/pyproject.toml index 958b5f7..be75c51 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -122,6 +122,7 @@ dev = [ "pep8-naming (>=0.15.1,<0.16.0)", "pydoclint[flake8] (>=0.12.0,<0.13.0)", "ruff (>=0.17.6,<0.18.0)", + "tryceratops (>=2.4.1,<3.0.0)", ] test = [ @@ -267,6 +268,8 @@ select = [ "N8", # pydoclint => Docstring matches implementation "DOC", + # tryceratops => Clean exception handling + "TRY", # ======================================== # `ruff` only (no working `flake8` plugin) # ======================================== @@ -330,6 +333,8 @@ extend-ignore = [ "SIM901", # TODOs need neither an author nor an issue. "T002", "T003", + # Messages are written where the exceptions are raised. + "TRY003", ] per-file-ignores = [ @@ -577,6 +582,8 @@ select = [ "TD", # flake8-tidy-imports ("I25") => No relative imports "TID", + # tryceratops => Clean exception handling + "TRY", # ======================================= # Violations not covered by `flake8` above # ======================================= @@ -625,6 +632,8 @@ extend-ignore = [ "RUF100", # TODOs need neither an author nor an issue. "TD002", "TD003", + # Messages are written where the exceptions are raised. + "TRY003", ] diff --git a/uv.lock b/uv.lock index 31d18b5..670d7cd 100644 --- a/uv.lock +++ b/uv.lock @@ -3826,6 +3826,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/ad/66/0d785f0bc5e4315a96c989bb476d0fc07ea4f85132550c7b156ca2035d52/traitlets-5.16.1-py3-none-any.whl", hash = "sha256:f775618166caa0396c8e337099240f2bd3e5e917d203b2e6fbe21a58d3cb1f6b", size = 86211, upload-time = "2026-08-03T08:32:34.48Z" }, ] +[[package]] +name = "tryceratops" +version = "2.4.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "click" }, + { name = "rich" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/2a/d3/43c2c190bb6b01decc92d87538b451d7fe8070aaaf18aa1e166bf432754e/tryceratops-2.4.1.tar.gz", hash = "sha256:fbfc14650004e27cd1e55ebb7c76b43ced04a4d3b4cbe42aac9d71e4623ed84d", size = 20595, upload-time = "2024-10-30T16:42:40.97Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/27/b5/88caeba349f17b7fd37b61bc88f81c138b3b5149b4e2a9deec66eaad1bdb/tryceratops-2.4.1-py3-none-any.whl", hash = "sha256:271b92367be89b243918a56361618607d2a9aa4aa4ba766ecfabd5f98c00480c", size = 27378, upload-time = "2024-10-30T16:42:38.914Z" }, +] + [[package]] name = "typing-extensions" version = "4.16.0" @@ -3952,6 +3965,7 @@ dev = [ { name = "pre-commit" }, { name = "pydoclint", extra = ["flake8"] }, { name = "ruff" }, + { name = "tryceratops" }, ] docs = [ { name = "sphinx" }, @@ -4030,6 +4044,7 @@ dev = [ { name = "pre-commit", specifier = ">=4.7.0,<5.0.0" }, { name = "pydoclint", extras = ["flake8"], specifier = ">=0.12.0,<0.13.0" }, { name = "ruff", specifier = ">=0.17.6,<0.18.0" }, + { name = "tryceratops", specifier = ">=2.4.1,<3.0.0" }, ] docs = [ { name = "sphinx", specifier = ">=9.2.0,<10.0.0" }, -- 2.47.3 From 567bb713e2f35e367eb76bd1bc0806d919cd1919 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:43:49 +0100 Subject: [PATCH 29/31] Enable YTT in `flake8` and `ruff` --- noxfile.py | 1 + pyproject.toml | 5 +++++ uv.lock | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/noxfile.py b/noxfile.py index b1924fc..f003d9c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -191,6 +191,7 @@ def lint_code(session: nox.Session) -> None: # because otherwise it treats missing packages as `Any` ".", "flake8", + "flake8-2020", "flake8-annotations", "flake8-bandit", "flake8-black", diff --git a/pyproject.toml b/pyproject.toml index be75c51..9562345 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,6 +91,7 @@ dev = [ # Code Analyzers "flake8 (>=7.5.0,<8.0.0)", + "flake8-2020 (>=1.8.1,<2.0.0)", "flake8-annotations (>=3.3.1,<4.0.0)", "flake8-bandit (>=4.1.1,<5.0.0)", "flake8-black (>=0.5.0,<0.6.0)", @@ -212,6 +213,8 @@ select = [ # ======= # plugins # ======= + # flake8-2020 => Correct `sys.version` checks + "YTT", # flake8-annotations => Enforce type checking for functions "ANN0", "ANN2", "ANN3", # flake8-bandit => Common security issues @@ -584,6 +587,8 @@ select = [ "TID", # tryceratops => Clean exception handling "TRY", + # flake8-2020 => Correct `sys.version` checks + "YTT", # ======================================= # Violations not covered by `flake8` above # ======================================= diff --git a/uv.lock b/uv.lock index 670d7cd..b02ec76 100644 --- a/uv.lock +++ b/uv.lock @@ -884,6 +884,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/5d/57/a3adc5f380f50ef3d01014cb9d3b8c17b25de9b89def20d559def4fc3c4e/flake8-7.5.0-py2.py3-none-any.whl", hash = "sha256:637ea1a443a78ed6ee461725cdf71ca93bc5cde0abf25436dbebdc3880b4e078", size = 57487, upload-time = "2026-10-28T20:17:21.061Z" }, ] +[[package]] +name = "flake8-2020" +version = "1.8.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "flake8" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/cf/0b/e71a0d9efd854a631e2d51707676886997c73bec70c3c221b84601b976d2/flake8_2020-1.8.1.tar.gz", hash = "sha256:094ea95e8b614c3bd123fd4f007be28ec117ca57a6169903d4baaabe78e3e590", size = 4527, upload-time = "2023-06-10T19:05:11.43Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/36/f0/14c6c25768ddc81999733e7bed89e9285b273920505180155e351ed92dc5/flake8_2020-1.8.1-py2.py3-none-any.whl", hash = "sha256:59b6b8ac01cde10ef11b31a2c9aa15b4509d828ae115ee5be34464b9e4de4ea6", size = 4885, upload-time = "2023-06-10T19:05:09.965Z" }, +] + [[package]] name = "flake8-annotations" version = "3.3.1" @@ -3930,6 +3942,7 @@ dev = [ { name = "autoflake" }, { name = "black" }, { name = "flake8" }, + { name = "flake8-2020" }, { name = "flake8-annotations" }, { name = "flake8-bandit" }, { name = "flake8-black" }, @@ -4009,6 +4022,7 @@ dev = [ { name = "autoflake", specifier = ">=2.4.0,<3.0.0" }, { name = "black", specifier = ">=25.12.0,<26.0.0" }, { name = "flake8", specifier = ">=7.5.0,<8.0.0" }, + { name = "flake8-2020", specifier = ">=1.8.1,<2.0.0" }, { name = "flake8-annotations", specifier = ">=3.3.1,<4.0.0" }, { name = "flake8-bandit", specifier = ">=4.1.1,<5.0.0" }, { name = "flake8-black", specifier = ">=0.5.0,<0.6.0" }, -- 2.47.3 From 8d843895b744cd63a867e17f5abdbf8a4bcc70c4 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:50:05 +0100 Subject: [PATCH 30/31] Complete the `ruff`-only notes in the `flake8` section --- pyproject.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 9562345..b2790da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -278,12 +278,18 @@ select = [ # ======================================== # flake8-blind-except => No blind `except Exception:` # "BLE", + # eradicate => No commented-out code + # "ERA", # flynt => F-strings instead of `str.join()` # "FLY", # refurb => Modern idioms # "FURB", # flake8-logging-format => Lazy `logging` messages # "G", + # isort => Imports are sorted + # "I", + # flake8-import-conventions => Unified import aliases + # "ICN", # NumPy-specific rules => Modern `numpy` APIs # "NPY", # Perflint => No performance anti-patterns @@ -298,6 +304,8 @@ select = [ # "RUF", # flake8-self => No access to private members from outside # "SLF", + # flake8-print => No `print()` + # "T20", # pyupgrade => Modern syntax for the targeted Python version # "UP", ] -- 2.47.3 From 6ecbd6860a893433e275266402548903c06b0b38 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Mon, 30 Nov 2026 23:50:12 +0100 Subject: [PATCH 31/31] Add the `flake8`-only notes to the `ruff` section --- pyproject.toml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index b2790da..10333eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -630,6 +630,17 @@ select = [ "T20", # pyupgrade => Modern syntax for the targeted Python version "UP", + # ===================================== + # `flake8` only (no `ruff` counterpart) + # ===================================== + # flake8-black => Complain if black would make changes + # "BLK", + # pydoclint => Docstring matches implementation + # "DOC", + # flake8-broken-line => No \ to end a line + # "N400", + # flake8-sfs => Use f-strings as the only type of string formatting + # "SFS", ] extend-ignore = [ -- 2.47.3