From dcb9cea4603af504b13e62209eb10ea15c9d8ff9 Mon Sep 17 00:00:00 2001 From: the Mulhern Date: Mon, 21 Sep 2026 12:08:12 -0400 Subject: [PATCH 1/2] Add PyFlakes to ruff linter emulators Assisted-by: Claude:claude-sonnet-4-5 Signed-off-by: the Mulhern --- pyproject.toml | 2 +- src/justbytes/__init__.py | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 10bbc1d..286a119 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ target-version = "py312" line-length = 88 [tool.ruff.lint] -select = ["PL"] +select = ["F", "PL"] [tool.ruff.lint.isort] known-first-party = ["justbases"] diff --git a/src/justbytes/__init__.py b/src/justbytes/__init__.py index 7f44280..6f4c1a6 100644 --- a/src/justbytes/__init__.py +++ b/src/justbytes/__init__.py @@ -81,32 +81,33 @@ # pylint: disable=wrong-import-position # CONFIGURATION -from ._config import ( - BaseConfig, - Config, - DigitsConfig, - DisplayConfig, - StringConfig, - StripConfig, - ValueConfig, -) +from ._config import BaseConfig as BaseConfig +from ._config import Config as Config +from ._config import DigitsConfig as DigitsConfig +from ._config import DisplayConfig as DisplayConfig +from ._config import StringConfig as StringConfig +from ._config import StripConfig as StripConfig +from ._config import ValueConfig as ValueConfig # ROUNDING CONSTANTS # UNIT CONSTANTS -from ._constants import ROUNDING_METHODS, UNITS, B +from ._constants import ROUNDING_METHODS as ROUNDING_METHODS +from ._constants import UNITS as UNITS +from ._constants import B as B from ._constants import BinaryUnits as _BinaryUnits from ._constants import DecimalUnits as _DecimalUnits from ._constants import RoundingMethods as _RoundingMethods # EXCEPTIONS -from ._errors import RangeError, RangeValueError +from ._errors import RangeError as RangeError +from ._errors import RangeValueError as RangeValueError # SIZE -from ._size import Range -from ._sizes import AI +from ._size import Range as Range +from ._sizes import AI as AI # VERSION -from .version import __version__ +from .version import __version__ as __version__ KB = _DecimalUnits.KB MB = _DecimalUnits.MB From bbcebc3610fc2e99f7362a27336a0d3c8ee3a4bf Mon Sep 17 00:00:00 2001 From: the Mulhern Date: Mon, 21 Sep 2026 13:00:55 -0400 Subject: [PATCH 2/2] Add bugbear to ruff linter emulators Assisted-by: Claude:claude-sonnet-4-5 Signed-off-by: the Mulhern --- pyproject.toml | 2 +- src/justbytes/_config.py | 6 +++--- src/justbytes/_constants.py | 18 +++++++++++++----- .../test_size/test_operations.py | 16 ++++++++-------- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 286a119..470ed2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ target-version = "py312" line-length = 88 [tool.ruff.lint] -select = ["F", "PL"] +select = ["B", "F", "PL"] [tool.ruff.lint.isort] known-first-party = ["justbases"] diff --git a/src/justbytes/_config.py b/src/justbytes/_config.py index 0806ce0..a7ef9d8 100644 --- a/src/justbytes/_config.py +++ b/src/justbytes/_config.py @@ -55,9 +55,9 @@ class DisplayConfig(justbases.DisplayConfig): def __init__( self, show_approx_str=True, - base_config=BaseConfig(), - digits_config=DigitsConfig(), - strip_config=StripConfig(), + base_config=BaseConfig(), # noqa: B008 # FIXME + digits_config=DigitsConfig(), # noqa: B008 # FIXME + strip_config=StripConfig(), # noqa: B008 # FIXME ): """ Initializer. diff --git a/src/justbytes/_constants.py b/src/justbytes/_constants.py index 8d96b36..00cd9b9 100644 --- a/src/justbytes/_constants.py +++ b/src/justbytes/_constants.py @@ -22,7 +22,6 @@ * Size units, e.g., Ki, Mi """ -import abc from numbers import Rational import justbases @@ -57,16 +56,25 @@ def __int__(self): """ The universal unit, bytes. """ -class Units(metaclass=abc.ABCMeta): +class Units: """ Generic class for units. - """ - FACTOR = abc.abstractproperty(doc="factor for each unit") + Subclasses must define FACTOR (int) and _UNITS (list). + """ - _UNITS = abc.abstractproperty(doc="ordered list of units") + def __init_subclass__(cls, **kwargs): + super().__init_subclass__(**kwargs) + required_attrs = ["FACTOR", "_UNITS"] + for attr in required_attrs: + if not hasattr(cls, attr): + raise TypeError( + f"Can't instantiate abstract class {cls.__name__} " + f"without class attribute {attr}" + ) _MAX_EXPONENT = None + _UNITS = [] @classmethod def UNITS(cls): diff --git a/tests/test_deterministic/test_size/test_operations.py b/tests/test_deterministic/test_size/test_operations.py index 4a64872..522ba8d 100644 --- a/tests/test_deterministic/test_size/test_operations.py +++ b/tests/test_deterministic/test_size/test_operations.py @@ -49,30 +49,30 @@ def test_binary_operators_boolean(self): # < self.assertTrue(Range(0, MiB) < Range(32)) with self.assertRaises(RangeNonsensicalBinOpError): - Range(0) < 1 + Range(0) < 1 # noqa: B015 with self.assertRaises(RangeNonsensicalBinOpError): - 1 < Range(32, TiB) + 1 < Range(32, TiB) # noqa: B015 # <= self.assertTrue(Range(0, MiB) <= Range(32)) with self.assertRaises(RangeNonsensicalBinOpError): - Range(0) <= 1 + Range(0) <= 1 # noqa: B015 with self.assertRaises(RangeNonsensicalBinOpError): - 1 <= Range(32, TiB) + 1 <= Range(32, TiB) # noqa: B015 # > self.assertTrue(Range(32, MiB) > Range(32)) with self.assertRaises(RangeNonsensicalBinOpError): - Range(32) > 1 + Range(32) > 1 # noqa: B015 with self.assertRaises(RangeNonsensicalBinOpError): - 1 > Range(0, TiB) + 1 > Range(0, TiB) # noqa: B015 # >= self.assertTrue(Range(32, MiB) >= Range(32)) with self.assertRaises(RangeNonsensicalBinOpError): - Range(32) >= 1 + Range(32) >= 1 # noqa: B015 with self.assertRaises(RangeNonsensicalBinOpError): - 1 >= Range(0, TiB) + 1 >= Range(0, TiB) # noqa: B015 # != self.assertTrue(Range(32, MiB) != Range(32, GiB))