Skip to content

Commit cae82b7

Browse files
Improve error message formatting with ruff
1 parent 5f539ee commit cae82b7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

ligotimegps/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def __init__(self, seconds, nanoseconds=0):
9292
try:
9393
seconds = str(Decimal(seconds))
9494
except ArithmeticError:
95-
raise TypeError(f"invalid literal for {type(self).__name__}: {seconds}")
95+
msg = f"invalid literal for {type(self).__name__}: {seconds}"
96+
raise TypeError(msg)
9697
sign = -1 if seconds.startswith("-") else +1
9798
if "." in seconds:
9899
seconds, ns = seconds.split(".")
@@ -106,8 +107,11 @@ def __init__(self, seconds, nanoseconds=0):
106107
nanoseconds += seconds.gpsNanoSeconds
107108
seconds = seconds.gpsSeconds
108109
else:
109-
raise TypeError(f"cannot convert {seconds!r} ({seconds.__class__.__name__})"
110-
f" to {type(self).__name__}")
110+
msg = (
111+
f"cannot convert {seconds!r} ({seconds.__class__.__name__})"
112+
f" to {type(self).__name__}"
113+
)
114+
raise TypeError(msg)
111115
self._seconds = seconds + int(nanoseconds // 1000000000)
112116
self._nanoseconds = int(nanoseconds % 1000000000)
113117

ligotimegps/tests/test_ligotimegps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
def assert_almost_equal(a, b, places=7): # pragma: no cover
2626
if round(abs(a - b), places) == 0:
2727
return
28-
raise AssertionError(f"{a} != {b} within {places} places")
28+
msg = f"{a} != {b} within {places} places"
29+
raise AssertionError(msg)
2930

3031

3132
@pytest.mark.parametrize(("value", "sec", "nanosec"), (

0 commit comments

Comments
 (0)