From 476760384e326467d24650bd9305f5a992bb8f35 Mon Sep 17 00:00:00 2001 From: mulhern Date: Thu, 10 Sep 2026 21:03:14 -0400 Subject: [PATCH 1/2] Add bugbear linter to ruff linter emulations Signed-off-by: mulhern --- pyproject.toml | 2 +- src/stratis_cli/_actions/_data.py | 2 +- src/stratis_cli/_actions/_formatting.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 04b236190..1c577bb2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ target-version = "py312" line-length = 88 [tool.ruff.lint] -select = ["F", "PL"] +select = ["B", "F", "PL"] [tool.ruff.lint.isort] known-first-party = ["dbus_client_gen", "dbus_python_client_gen"] diff --git a/src/stratis_cli/_actions/_data.py b/src/stratis_cli/_actions/_data.py index 9d0da3ad2..3de1dbeb8 100644 --- a/src/stratis_cli/_actions/_data.py +++ b/src/stratis_cli/_actions/_data.py @@ -120,7 +120,7 @@ def _add_abs_path_assertion(klass, method_name, key): :param str method_name: the name of the method :param str key: the key at which the paths can be found in the arguments """ - method_class = getattr(klass, "Methods") + method_class = klass.Methods orig_method = getattr(method_class, method_name) def new_method(proxy, args): diff --git a/src/stratis_cli/_actions/_formatting.py b/src/stratis_cli/_actions/_formatting.py index bf93e093c..8569cc61a 100644 --- a/src/stratis_cli/_actions/_formatting.py +++ b/src/stratis_cli/_actions/_formatting.py @@ -136,7 +136,7 @@ def print_table( ) cell_widths.append(row_widths) - for row, row_widths in zip(row_entries, cell_widths): + for row, row_widths in zip(row_entries, cell_widths, strict=True): _print_row(file, row, row_widths, column_widths, alignment) print(file=file) From 1d24d7d6373e9988680e2f59e1bbe02d004879c6 Mon Sep 17 00:00:00 2001 From: the Mulhern Date: Fri, 11 Sep 2026 09:29:19 -0400 Subject: [PATCH 2/2] Use assert_never instead of assert for unreachable code It is observed by Python type analyzers like pyright and the assertion is not optimized away, as assert can be with some Python compilation flags. Assisted-by: Claude:claude-sonnet-4-5 Signed-off-by: the Mulhern --- src/stratis_cli/_alerts.py | 20 ++++++++++---------- src/stratis_cli/_parser/_shared.py | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/stratis_cli/_alerts.py b/src/stratis_cli/_alerts.py index 73ee2d7e7..e7ccffdfa 100644 --- a/src/stratis_cli/_alerts.py +++ b/src/stratis_cli/_alerts.py @@ -16,7 +16,7 @@ """ from enum import Enum, IntEnum -from typing import Dict, List, Optional, Union +from typing import Dict, List, Optional, Union, assert_never class Level(Enum): @@ -62,7 +62,7 @@ def explain(self) -> str: "any maintenance operations." ) - assert False, "impossible code reached" # pragma: no cover + assert_never(self) # pragma: no cover def summarize(self) -> str: """ @@ -74,7 +74,7 @@ def summarize(self) -> str: if self is PoolMaintenanceAlert.NO_POOL_CHANGES: return "Pool maintenance operations not possible" - assert False, "impossible code reached" # pragma: no cover + assert_never(self) # pragma: no cover class PoolAllocSpaceAlert(IntEnum): @@ -98,7 +98,7 @@ def explain(self) -> str: "to the pool." ) - assert False, "impossible code reached" # pragma: no cover + assert_never(self) # pragma: no cover def summarize(self) -> str: """ @@ -107,7 +107,7 @@ def summarize(self) -> str: if self is PoolAllocSpaceAlert.NO_ALLOC_SPACE: return "All devices fully allocated" - assert False, "impossible code reached" # pragma: no cover + assert_never(self) # pragma: no cover class PoolDeviceSizeChangeAlert(IntEnum): @@ -126,7 +126,7 @@ def __str__(self) -> str: if self is PoolDeviceSizeChangeAlert.DEVICE_SIZE_DECREASED: return f"{Level.WARNING}DS{str(self.value).zfill(3)}" - assert False, "impossible code reached" # pragma: no cover + assert_never(self) # pragma: no cover def explain(self) -> str: """ @@ -144,7 +144,7 @@ def explain(self) -> str: "decreased in size." ) - assert False, "impossible code reached" # pragma: no cover + assert_never(self) # pragma: no cover def summarize(self) -> str: """ @@ -156,7 +156,7 @@ def summarize(self) -> str: if self is PoolDeviceSizeChangeAlert.DEVICE_SIZE_DECREASED: return "A device in this pool has decreased in size." - assert False, "impossible code reached" # pragma: no cover + assert_never(self) # pragma: no cover class PoolEncryptionAlert(IntEnum): @@ -188,7 +188,7 @@ def explain(self) -> str: "encryption layer needs to be modified." ) - assert False, "impossible code reached" # pragma: no cover + assert_never(self) # pragma: no cover def summarize(self) -> str: """ @@ -199,7 +199,7 @@ def summarize(self) -> str: if self is PoolEncryptionAlert.VOLUME_KEY_STATUS_UNKNOWN: return "Volume key status unknown" - assert False, "impossible code reached" # pragma: no cover + assert_never(self) # pragma: no cover CLASSES = [ diff --git a/src/stratis_cli/_parser/_shared.py b/src/stratis_cli/_parser/_shared.py index 2ff08e039..e8859a35b 100644 --- a/src/stratis_cli/_parser/_shared.py +++ b/src/stratis_cli/_parser/_shared.py @@ -18,6 +18,7 @@ import argparse import copy import re +from typing import assert_never from uuid import UUID from justbytes import B, GiB, KiB, MiB, PiB, Range, TiB @@ -62,7 +63,7 @@ def _unit_map(unit_specifier): return TiB if unit_specifier == "PiB": return PiB - assert False, f'Unknown unit specifier "{unit_specifier}"' + assert_never(unit_specifier) def parse_range(values):