Skip to content

Commit fe912f6

Browse files
Replace assert statements with proper exception handling (#54)
2 parents 4846a6d + 7956ed4 commit fe912f6

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
## New Features
1212

13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
13+
* Replace assert statements with proper exception handling
1414

1515
## Bug Fixes
1616

src/frequenz/client/electricity_trading/_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def validate_decimal_places(value: Decimal, decimal_places: int, name: str) -> N
6666
ValueError: If the value has more decimal places than allowed.
6767
or the value is not a valid decimal number.
6868
"""
69-
assert decimal_places >= 0, "The decimal places must be a non-negative integer."
69+
if decimal_places < 0:
70+
raise ValueError("The decimal places must be a non-negative integer.")
7071

7172
try:
7273
exponent = int(value.as_tuple().exponent)
@@ -287,7 +288,7 @@ async def stream_public_trades(
287288
return self._public_trades_streams[public_trade_filter].new_receiver()
288289

289290
def validate_params(
290-
# pylint: disable=too-many-arguments, too-many-positional-arguments
291+
# pylint: disable=too-many-arguments, too-many-positional-arguments, too-many-branches
291292
self,
292293
price: Price | None | _Sentinel = NO_VALUE,
293294
quantity: Energy | None | _Sentinel = NO_VALUE,
@@ -359,9 +360,8 @@ def validate_params(
359360
if valid_until < datetime.now(timezone.utc):
360361
raise ValueError("valid_until must be in the future")
361362
if order_type is not None:
362-
assert order_type == OrderType.LIMIT, NotImplementedError(
363-
"Currently only limit orders are supported"
364-
)
363+
if order_type != OrderType.LIMIT:
364+
raise NotImplementedError("Currently only limit orders are supported.")
365365

366366
async def create_gridpool_order(
367367
# pylint: disable=too-many-arguments, too-many-positional-arguments, too-many-locals

tests/test_validate_decimal_places.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ def test_invalid_inputs(self) -> None:
3434
validate_decimal_places(Decimal("NaN"), 2, "Test Value")
3535
with self.assertRaises(ValueError):
3636
validate_decimal_places(Decimal("Infinity"), 2, "Test Value")
37-
with self.assertRaises(AssertionError):
37+
with self.assertRaises(ValueError):
3838
validate_decimal_places(Decimal("123.45"), -1, "Test Value")

0 commit comments

Comments
 (0)