Refactors type hints for clarity
Updates type hints in `crud.py`, `helpers.py`, and `models.py` for improved readability and maintainability. Replaces `Merchant | None` with `Optional[Merchant]` and `list[X]` with `List[X]` for consistency with standard Python typing practices.
This commit is contained in:
parent
429522adba
commit
e8ddc4b697
5 changed files with 122 additions and 115 deletions
18
services.py
18
services.py
|
|
@ -1,7 +1,8 @@
|
|||
import asyncio
|
||||
import json
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from bolt11 import decode
|
||||
from lnbits.bolt11 import decode
|
||||
from lnbits.core.crud import get_wallet
|
||||
from lnbits.core.services import create_invoice, websocket_updater
|
||||
from loguru import logger
|
||||
|
|
@ -59,7 +60,7 @@ from .nostr.event import NostrEvent
|
|||
|
||||
async def create_new_order(
|
||||
merchant_public_key: str, data: PartialOrder
|
||||
) -> PaymentRequest | None:
|
||||
) -> Optional[PaymentRequest]:
|
||||
merchant = await get_merchant_by_pubkey(merchant_public_key)
|
||||
assert merchant, "Cannot find merchant for order!"
|
||||
|
||||
|
|
@ -144,7 +145,7 @@ async def update_merchant_to_nostr(
|
|||
merchant: Merchant, delete_merchant=False
|
||||
) -> Merchant:
|
||||
stalls = await get_stalls(merchant.id)
|
||||
event: NostrEvent | None = None
|
||||
event: Optional[NostrEvent] = None
|
||||
for stall in stalls:
|
||||
assert stall.id
|
||||
products = await get_products(merchant.id, stall.id)
|
||||
|
|
@ -229,7 +230,7 @@ async def notify_client_of_order_status(
|
|||
|
||||
async def update_products_for_order(
|
||||
merchant: Merchant, order: Order
|
||||
) -> tuple[bool, str]:
|
||||
) -> Tuple[bool, str]:
|
||||
product_ids = [i.product_id for i in order.items]
|
||||
success, products, message = await compute_products_new_quantity(
|
||||
merchant.id, product_ids, order.items
|
||||
|
|
@ -297,9 +298,9 @@ async def send_dm(
|
|||
|
||||
|
||||
async def compute_products_new_quantity(
|
||||
merchant_id: str, product_ids: list[str], items: list[OrderItem]
|
||||
) -> tuple[bool, list[Product], str]:
|
||||
products: list[Product] = await get_products_by_ids(merchant_id, product_ids)
|
||||
merchant_id: str, product_ids: List[str], items: List[OrderItem]
|
||||
) -> Tuple[bool, List[Product], str]:
|
||||
products: List[Product] = await get_products_by_ids(merchant_id, product_ids)
|
||||
|
||||
for p in products:
|
||||
required_quantity = next(
|
||||
|
|
@ -332,6 +333,7 @@ async def process_nostr_message(msg: str):
|
|||
return
|
||||
_, event = rest
|
||||
event = NostrEvent(**event)
|
||||
|
||||
if event.kind == 0:
|
||||
await _handle_customer_profile_update(event)
|
||||
elif event.kind == 4:
|
||||
|
|
@ -502,7 +504,7 @@ async def _handle_outgoing_dms(
|
|||
|
||||
async def _handle_incoming_structured_dm(
|
||||
merchant: Merchant, dm: DirectMessage, json_data: dict
|
||||
) -> tuple[DirectMessageType, str | None]:
|
||||
) -> Tuple[DirectMessageType, Optional[str]]:
|
||||
try:
|
||||
if dm.type == DirectMessageType.CUSTOMER_ORDER.value and merchant.config.active:
|
||||
json_resp = await _handle_new_order(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue