chore: get rid of mypy notes and typecheck more functions (#3257)

This commit is contained in:
dni ⚡ 2025-07-09 11:08:48 +02:00
parent 1a02095758
commit 256a8098c6
No known key found for this signature in database
GPG key ID: D1F416F29AD26E87
8 changed files with 23 additions and 23 deletions

View file

@ -448,7 +448,7 @@ def register_ext_routes(app: FastAPI, ext: Extension) -> None:
app.include_router(router=ext_route, prefix=prefix)
async def check_and_register_extensions(app: FastAPI):
async def check_and_register_extensions(app: FastAPI) -> None:
await check_installed_extensions(app)
for ext in await get_valid_extensions(False):
try:
@ -458,7 +458,7 @@ async def check_and_register_extensions(app: FastAPI):
logger.error(f"Could not load extension `{ext.code}`: {exc!s}")
def register_async_tasks():
def register_async_tasks() -> None:
create_permanent_task(wait_for_audit_data)
create_permanent_task(wait_notification_messages)

View file

@ -28,7 +28,7 @@ from lnbits.helpers import check_callback_url, is_valid_email_address
from lnbits.settings import settings
from lnbits.utils.nostr import normalize_private_key
notifications_queue: asyncio.Queue = asyncio.Queue()
notifications_queue: asyncio.Queue[NotificationMessage] = asyncio.Queue()
def enqueue_notification(message_type: NotificationType, values: dict) -> None:
@ -42,8 +42,8 @@ def enqueue_notification(message_type: NotificationType, values: dict) -> None:
logger.error(f"Error enqueuing notification: {e}")
async def process_next_notification():
notification_message: NotificationMessage = await notifications_queue.get()
async def process_next_notification() -> None:
notification_message = await notifications_queue.get()
message_type, text = _notification_message_to_text(notification_message)
await send_notification(text, message_type)

View file

@ -13,7 +13,7 @@ from lnbits.core.crud.audit import delete_expired_audit_entries
from lnbits.core.crud.payments import get_payments_status_count
from lnbits.core.crud.users import get_accounts
from lnbits.core.crud.wallets import get_wallets_count
from lnbits.core.models import AuditEntry
from lnbits.core.models.audit import AuditEntry
from lnbits.core.models.extensions import InstallableExtension
from lnbits.core.models.notifications import NotificationType
from lnbits.core.services.funding_source import (
@ -31,10 +31,10 @@ from lnbits.settings import settings
from lnbits.tasks import create_unique_task
from lnbits.utils.exchange_rates import btc_rates
audit_queue: asyncio.Queue = asyncio.Queue()
audit_queue: asyncio.Queue[AuditEntry] = asyncio.Queue()
async def run_by_the_minute_tasks():
async def run_by_the_minute_tasks() -> None:
minute_counter = 0
while settings.lnbits_running:
status_minutes = settings.lnbits_notification_server_status_hours * 60
@ -69,7 +69,7 @@ async def run_by_the_minute_tasks():
await asyncio.sleep(60)
async def _notify_server_status():
async def _notify_server_status() -> None:
accounts = await get_accounts(filters=Filters(limit=0))
wallets_count = await get_wallets_count()
payments = await get_payments_status_count()
@ -90,7 +90,7 @@ async def _notify_server_status():
enqueue_notification(NotificationType.server_status, values)
async def wait_for_paid_invoices(invoice_paid_queue: asyncio.Queue):
async def wait_for_paid_invoices(invoice_paid_queue: asyncio.Queue) -> None:
"""
This worker dispatches events to all extensions and dispatches webhooks.
"""
@ -103,13 +103,13 @@ async def wait_for_paid_invoices(invoice_paid_queue: asyncio.Queue):
await send_payment_notification(wallet, payment)
async def wait_for_audit_data():
async def wait_for_audit_data() -> None:
"""
Waits for audit entries to be pushed to the queue.
Then it inserts the entries into the DB.
"""
while settings.lnbits_running:
data: AuditEntry = await audit_queue.get()
data = await audit_queue.get()
try:
await create_audit_entry(data)
except Exception as ex:
@ -117,7 +117,7 @@ async def wait_for_audit_data():
await asyncio.sleep(3)
async def wait_notification_messages():
async def wait_notification_messages() -> None:
while settings.lnbits_running:
try:
@ -127,7 +127,7 @@ async def wait_notification_messages():
await asyncio.sleep(3)
async def purge_audit_data():
async def purge_audit_data() -> None:
"""
Remove audit entries which have passed their retention period.
"""
@ -141,7 +141,7 @@ async def purge_audit_data():
await asyncio.sleep(60 * 60)
async def collect_exchange_rates_data():
async def collect_exchange_rates_data() -> None:
"""
Collect exchange rates data. Used for monitoring only.
"""

View file

@ -7,7 +7,7 @@ from typing import Optional
import httpx
from loguru import logger
from pydantic import BaseModel
from websockets.legacy.client import WebSocketClientProtocol, connect
from websockets.legacy.client import connect
from websockets.typing import Subprotocol
from lnbits import bolt11
@ -48,7 +48,7 @@ class BlinkWallet(Wallet):
"payload": {"X-API-KEY": settings.blink_token},
}
self.client = httpx.AsyncClient(base_url=self.endpoint, headers=self.auth)
self.ws: Optional[WebSocketClientProtocol] = None
self.ws = None
self._wallet_id = None
@property

View file

@ -63,7 +63,7 @@ class BoltzWallet(Wallet):
channel = grpc.aio.insecure_channel(settings.boltz_client_endpoint)
self.rpc = boltzrpc_pb2_grpc.BoltzStub(channel)
self.wallet_id: int = 0
self.wallet_id = 0
# Auto-create wallet if running in Docker mode
async def _init_boltz_wallet():

View file

@ -62,7 +62,7 @@ class NWCWallet(Wallet):
# interval in seconds between checks for pending payments
self.pending_payments_lookup_interval = 10
# track paid invoices for paid_invoices_stream
self.paid_invoices_queue: asyncio.Queue = asyncio.Queue(0)
self.paid_invoices_queue = asyncio.Queue(0)
# This task periodically checks if pending payments have been settled
self.pending_payments_lookup_task = asyncio.create_task(
self._handle_pending_payments()

View file

@ -27,7 +27,7 @@ class TokenBucket:
Token bucket rate limiter for Strike API endpoints.
"""
def __init__(self, rate: int, period_seconds: int):
def __init__(self, rate: int, period_seconds: int) -> None:
"""
Initialize a token bucket.
@ -77,7 +77,7 @@ class StrikeWallet(Wallet):
# construction / teardown #
# --------------------------------------------------------------------- #
def __init__(self):
def __init__(self) -> None:
if not settings.strike_api_endpoint:
raise ValueError("Missing strike_api_endpoint")
if not settings.strike_api_key:
@ -120,7 +120,7 @@ class StrikeWallet(Wallet):
self._cached_balance_ts: float = 0.0
self._cache_ttl = 30 # seconds
async def cleanup(self):
async def cleanup(self) -> None:
try:
await self.client.aclose()
except Exception:

View file

@ -81,7 +81,7 @@ async def test_crud_search_payments():
user = await create_user_account()
wallet = await create_wallet(user_id=user.id)
filters: Filters = Filters(
filters = Filters(
search="",
model=PaymentFilters,
)