From 3fb7ec0bdc8de7d0aee553d4491f3274692afbd1 Mon Sep 17 00:00:00 2001 From: Splines Date: Fri, 15 Mar 2024 16:26:13 +0100 Subject: [PATCH] Fix more pylint warnings --- src/application/helpers.py | 16 +++++----------- src/application/rounder.py | 3 ++- src/domain/uncertainty.py | 4 +--- tests/playground.py | 2 +- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/application/helpers.py b/src/application/helpers.py index 15aa9230..436f5cd1 100644 --- a/src/application/helpers.py +++ b/src/application/helpers.py @@ -1,6 +1,5 @@ import math - _NUMBER_TO_WORD = { 0: "zero", 1: "one", @@ -49,21 +48,16 @@ def round_to_n_decimal_places(cls, value: float, n: int): @classmethod def number_to_word(cls, number: int) -> str: - if number >= 0 and number <= 19: + if 0 <= number <= 19: return _NUMBER_TO_WORD[number] - elif number >= 0 and number <= 99: + if 0 <= number <= 99: tens = number // 10 * 10 ones = number % 10 if ones == 0: return _NUMBER_TO_WORD[tens] - else: - return ( - _NUMBER_TO_WORD[tens] - + _NUMBER_TO_WORD[ones][0].upper() - + _NUMBER_TO_WORD[ones][1:] - ) - else: - raise RuntimeError("Runtime error.") + return _NUMBER_TO_WORD[tens] + cls.capitalize(_NUMBER_TO_WORD[ones]) + + raise ValueError(f"For variable names, only use numbers between 0 and 99. Got {number}.") @classmethod def capitalize(cls, s: str) -> str: diff --git a/src/application/rounder.py b/src/application/rounder.py index c458a747..b812c441 100644 --- a/src/application/rounder.py +++ b/src/application/rounder.py @@ -14,6 +14,7 @@ class RoundingConfig: decimal_places_fallback: int +# pylint: disable-next=too-few-public-methods class _Rounder: @classmethod @@ -114,7 +115,7 @@ def _round_result(cls, result: _Result, config: RoundingConfig) -> None: else: u.uncertainty.set_sigfigs(2) - min_exponent = min([u.uncertainty.get_min_exponent() for u in uncertainties]) + min_exponent = min(u.uncertainty.get_min_exponent() for u in uncertainties) value.set_min_exponent(min_exponent) # Rounding hierarchy 7: diff --git a/src/domain/uncertainty.py b/src/domain/uncertainty.py index 91654a91..5f47af3e 100644 --- a/src/domain/uncertainty.py +++ b/src/domain/uncertainty.py @@ -1,6 +1,7 @@ from domain.value import _Value +# pylint: disable-next=too-few-public-methods class _Uncertainty: """ A named uncertainty value, e.g. a systematic uncertainty of ±0.1cm @@ -16,6 +17,3 @@ class _Uncertainty: def __init__(self, uncertainty: _Value, name: str = ""): self.uncertainty = uncertainty self.name = name - - def value(self) -> _Value: - return self.uncertainty diff --git a/tests/playground.py b/tests/playground.py index bac54ab4..9cb5b792 100644 --- a/tests/playground.py +++ b/tests/playground.py @@ -28,7 +28,7 @@ # wiz.res("", 42.0).print() # -> Error: "name must not be empty" -wiz.res("a1", 1.0, r"\mm") +wiz.res("a99", 1.0, r"\mm") # a: 1.0 \mm wiz.res("1 b", 1.0, 0.01, r"\per\mm\cubed").print()