Skip to content

Commit dd12bf4

Browse files
committed
Rename _Sentinel_NoValue
This makes its purpose clear. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent f33a97f commit dd12bf4

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/frequenz/client/electricity_trading/_client.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@
5757
_logger = logging.getLogger(__name__)
5858

5959

60-
class _Sentinel:
60+
class _NoValue:
6161
"""A unique object to signify 'no value passed'."""
6262

6363

64-
NO_VALUE = _Sentinel()
64+
NO_VALUE = _NoValue()
6565
PRECISION_DECIMAL_PRICE = 2
6666
PRECISION_DECIMAL_QUANTITY = 1
6767

@@ -391,14 +391,14 @@ def validate_params(
391391
# pylint: disable=too-many-arguments, too-many-branches
392392
self,
393393
*,
394-
price: Price | None | _Sentinel = NO_VALUE,
395-
quantity: Power | None | _Sentinel = NO_VALUE,
396-
stop_price: Price | None | _Sentinel = NO_VALUE,
397-
peak_price_delta: Price | None | _Sentinel = NO_VALUE,
398-
display_quantity: Power | None | _Sentinel = NO_VALUE,
394+
price: Price | None | _NoValue = NO_VALUE,
395+
quantity: Power | None | _NoValue = NO_VALUE,
396+
stop_price: Price | None | _NoValue = NO_VALUE,
397+
peak_price_delta: Price | None | _NoValue = NO_VALUE,
398+
display_quantity: Power | None | _NoValue = NO_VALUE,
399399
delivery_period: DeliveryPeriod | None = None,
400-
valid_until: datetime | None | _Sentinel = NO_VALUE,
401-
execution_option: OrderExecutionOption | None | _Sentinel = NO_VALUE,
400+
valid_until: datetime | None | _NoValue = NO_VALUE,
401+
execution_option: OrderExecutionOption | None | _NoValue = NO_VALUE,
402402
order_type: OrderType | None = None,
403403
) -> None:
404404
"""
@@ -423,34 +423,34 @@ def validate_params(
423423
ValueError: If the parameters are invalid.
424424
NotImplementedError: If the order type is not supported.
425425
"""
426-
if not isinstance(price, _Sentinel) and price is not None:
426+
if not isinstance(price, _NoValue) and price is not None:
427427
if price.amount < MIN_PRICE or price.amount > MAX_PRICE:
428428
raise ValueError(f"Price must be between {MIN_PRICE} and {MAX_PRICE}.")
429429
validate_decimal_places(price.amount, PRECISION_DECIMAL_PRICE, "price")
430-
if not isinstance(quantity, _Sentinel) and quantity is not None:
430+
if not isinstance(quantity, _NoValue) and quantity is not None:
431431
if quantity.mw <= 0:
432432
raise ValueError("Quantity must be strictly positive")
433433
if quantity.mw < MIN_QUANTITY_MW:
434434
raise ValueError(f"Quantity must be at least {MIN_QUANTITY_MW} MW.")
435435
validate_decimal_places(quantity.mw, PRECISION_DECIMAL_QUANTITY, "quantity")
436-
if not isinstance(stop_price, _Sentinel) and stop_price is not None:
436+
if not isinstance(stop_price, _NoValue) and stop_price is not None:
437437
raise NotImplementedError(
438438
"STOP_LIMIT orders are not supported yet, so stop_price cannot be set."
439439
)
440-
if not isinstance(peak_price_delta, _Sentinel) and peak_price_delta is not None:
440+
if not isinstance(peak_price_delta, _NoValue) and peak_price_delta is not None:
441441
raise NotImplementedError(
442442
"ICEBERG orders are not supported yet, so peak_price_delta cannot be set."
443443
)
444-
if not isinstance(display_quantity, _Sentinel) and display_quantity is not None:
444+
if not isinstance(display_quantity, _NoValue) and display_quantity is not None:
445445
raise NotImplementedError(
446446
"ICEBERG orders are not supported yet, so display_quantity cannot be set."
447447
)
448448
if delivery_period is not None:
449449
if delivery_period.start < datetime.now(timezone.utc):
450450
raise ValueError("delivery_period must be in the future")
451-
if not isinstance(valid_until, _Sentinel) and valid_until is not None:
451+
if not isinstance(valid_until, _NoValue) and valid_until is not None:
452452
if (
453-
not isinstance(execution_option, _Sentinel)
453+
not isinstance(execution_option, _NoValue)
454454
and execution_option is not None
455455
):
456456
if execution_option in [
@@ -565,15 +565,15 @@ async def update_gridpool_order(
565565
gridpool_id: int,
566566
*,
567567
order_id: int,
568-
price: Price | None | _Sentinel = NO_VALUE,
569-
quantity: Power | None | _Sentinel = NO_VALUE,
570-
stop_price: Price | None | _Sentinel = NO_VALUE,
571-
peak_price_delta: Price | None | _Sentinel = NO_VALUE,
572-
display_quantity: Power | None | _Sentinel = NO_VALUE,
573-
execution_option: OrderExecutionOption | None | _Sentinel = NO_VALUE,
574-
valid_until: datetime | None | _Sentinel = NO_VALUE,
575-
payload: dict[str, struct_pb2.Value] | None | _Sentinel = NO_VALUE,
576-
tag: str | None | _Sentinel = NO_VALUE,
568+
price: Price | None | _NoValue = NO_VALUE,
569+
quantity: Power | None | _NoValue = NO_VALUE,
570+
stop_price: Price | None | _NoValue = NO_VALUE,
571+
peak_price_delta: Price | None | _NoValue = NO_VALUE,
572+
display_quantity: Power | None | _NoValue = NO_VALUE,
573+
execution_option: OrderExecutionOption | None | _NoValue = NO_VALUE,
574+
valid_until: datetime | None | _NoValue = NO_VALUE,
575+
payload: dict[str, struct_pb2.Value] | None | _NoValue = NO_VALUE,
576+
tag: str | None | _NoValue = NO_VALUE,
577577
timeout: timedelta | None = None,
578578
) -> OrderDetail:
579579
"""
@@ -638,21 +638,21 @@ async def update_gridpool_order(
638638
update_mask = field_mask_pb2.FieldMask(paths=paths)
639639

640640
update_order_fields = UpdateOrder(
641-
price=None if isinstance(price, _Sentinel) else price,
642-
quantity=None if isinstance(quantity, _Sentinel) else quantity,
643-
stop_price=None if isinstance(stop_price, _Sentinel) else stop_price,
641+
price=None if isinstance(price, _NoValue) else price,
642+
quantity=None if isinstance(quantity, _NoValue) else quantity,
643+
stop_price=None if isinstance(stop_price, _NoValue) else stop_price,
644644
peak_price_delta=(
645-
None if isinstance(peak_price_delta, _Sentinel) else peak_price_delta
645+
None if isinstance(peak_price_delta, _NoValue) else peak_price_delta
646646
),
647647
display_quantity=(
648-
None if isinstance(display_quantity, _Sentinel) else display_quantity
648+
None if isinstance(display_quantity, _NoValue) else display_quantity
649649
),
650650
execution_option=(
651-
None if isinstance(execution_option, _Sentinel) else execution_option
651+
None if isinstance(execution_option, _NoValue) else execution_option
652652
),
653-
valid_until=(None if isinstance(valid_until, _Sentinel) else valid_until),
654-
payload=None if isinstance(payload, _Sentinel) else payload,
655-
tag=None if isinstance(tag, _Sentinel) else tag,
653+
valid_until=(None if isinstance(valid_until, _NoValue) else valid_until),
654+
payload=None if isinstance(payload, _NoValue) else payload,
655+
tag=None if isinstance(tag, _NoValue) else tag,
656656
)
657657

658658
try:

0 commit comments

Comments
 (0)