chore: update pyright to latest and fix new issues (#3978)
What changed, and why it matters
This commit is a routine developer maintenance task: upgrading the Pyright static type checker to a newer version and fixing the new type-check warnings it produced. There are no functional code changes intended to alter behavior, and nothing in the commit suggests a security fix or vulnerability.
No security action required. Treat as normal dependency/tooling maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff updates package.json/package-lock.json from pyright 1.1.289 to 1.1.409 and adds type annotations, casts, and # type: ignore comments across Python source and test files to satisfy the newer type checker. Notable patterns include: adding type: ignore[reportIncompatibleVariableOverride] on NamedTuple subclass overrides, adding type: ignore[reportMissingImports] for optional SDK imports, renaming a parameter from bolt11_invoice to bolt11 to avoid shadowing the imported bolt11 module, adding casts in tests, and annotating previously untyped dict variables. No runtime logic changes are evident.
Changed components
lnbits/fiat/base.pylnbits/settings.pylnbits/wallets/base.pylnbits/wallets/blink.pylnbits/wallets/breez.pylnbits/wallets/breez_liquid.pylnbits/wallets/fake.pylnbits/wallets/lndgrpc.pypackage.jsonpackage-lock.jsontests/api/test_lnurl_api.pytests/api/test_payment_api.pytests/unit/test_services_lnurl.pytests/unit/test_services_users.pytests/unit/test_settings.pytests/wallets/test_blink.pytests/wallets/test_rpc_wallets.pyInspect captured patch +57 / −43
diff --git a/lnbits/fiat/base.py b/lnbits/fiat/base.py
index 126ed4d..15e39fb 100644
--- a/lnbits/fiat/base.py
+++ b/lnbits/fiat/base.py
@@ -131,15 +131,15 @@ class FiatSubscriptionResponse(BaseModel):
class FiatPaymentSuccessStatus(FiatPaymentStatus):
- paid = True
+ paid = True # type: ignore[reportIncompatibleVariableOverride]
class FiatPaymentFailedStatus(FiatPaymentStatus):
- paid = False
+ paid = False # type: ignore[reportIncompatibleVariableOverride]
class FiatPaymentPendingStatus(FiatPaymentStatus):
- paid = None
+ paid = None # type: ignore[reportIncompatibleVariableOverride]
class FiatProvider(ABC):
diff --git a/lnbits/settings.py b/lnbits/settings.py
index 4923e8b..49e9eb5 100644
--- a/lnbits/settings.py
+++ b/lnbits/settings.py
@@ -1047,7 +1047,7 @@ class EditableSettings(
class UpdateSettings(EditableSettings):
- class Config:
+ class Config(EditableSettings.Config):
extra = Extra.forbid
@@ -1198,11 +1198,11 @@ class ReadOnlySettings(
class Settings(EditableSettings, ReadOnlySettings, TransientSettings, BaseSettings):
- class Config:
+ class Config(EditableSettings.Config, BaseSettings.Config): # type: ignore[misc]
env_file = ".env"
env_file_encoding = "utf-8"
case_sensitive = False
- json_loads = list_parse_fallback
+ json_loads = list_parse_fallback # type: ignore[assignment]
def is_user_allowed(self, user_id: str) -> bool:
return (
diff --git a/lnbits/wallets/base.py b/lnbits/wallets/base.py
index 9051794..4d1d81b 100644
--- a/lnbits/wallets/base.py
+++ b/lnbits/wallets/base.py
@@ -94,15 +94,15 @@ class PaymentStatus(NamedTuple):
class PaymentSuccessStatus(PaymentStatus):
- paid = True
+ paid = True # type: ignore[reportIncompatibleVariableOverride]
class PaymentFailedStatus(PaymentStatus):
- paid = False
+ paid = False # type: ignore[reportIncompatibleVariableOverride]
class PaymentPendingStatus(PaymentStatus):
- paid = None
+ paid = None # type: ignore[reportIncompatibleVariableOverride]
class Wallet(ABC):
diff --git a/lnbits/wallets/blink.py b/lnbits/wallets/blink.py
index be73608..edc7d1c 100644
--- a/lnbits/wallets/blink.py
+++ b/lnbits/wallets/blink.py
@@ -8,7 +8,7 @@ from loguru import logger
from pydantic import BaseModel
from websockets import Subprotocol, connect
-from lnbits import bolt11
+from lnbits import bolt11 as bolt11_lib
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
@@ -164,15 +164,13 @@ class BlinkWallet(Wallet):
ok=False, error_message=f"Unable to connect to {self.endpoint}."
)
- async def pay_invoice(
- self, bolt11_invoice: str, fee_limit_msat: int
- ) -> PaymentResponse:
+ async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse:
# https://dev.blink.sv/api/btc-ln-send
# Future: add check fee estimate is < fee_limit_msat before paying invoice
payment_variables = {
"input": {
- "paymentRequest": bolt11_invoice,
+ "paymentRequest": bolt11,
"walletId": self.wallet_id,
"memo": "Payment memo",
}
@@ -190,7 +188,7 @@ class BlinkWallet(Wallet):
error_message = errors[0].get("message")
return PaymentResponse(ok=False, error_message=error_message)
- checking_id = bolt11.decode(bolt11_invoice).payment_hash
+ checking_id = bolt11_lib.decode(bolt11).payment_hash
payment_status = await self.get_payment_status(checking_id)
fee_msat = payment_status.fee_msat
@@ -199,7 +197,7 @@ class BlinkWallet(Wallet):
ok=True, checking_id=checking_id, fee_msat=fee_msat, preimage=preimage
)
except Exception as exc:
- logger.info(f"Failed to pay invoice {bolt11_invoice}")
+ logger.info(f"Failed to pay invoice {bolt11}")
logger.warning(exc)
return PaymentResponse(
error_message=f"Unable to connect to {self.endpoint}."
diff --git a/lnbits/wallets/breez.py b/lnbits/wallets/breez.py
index bf6d59c..e32cb9b 100644
--- a/lnbits/wallets/breez.py
+++ b/lnbits/wallets/breez.py
@@ -19,7 +19,7 @@ else:
from bolt11 import Bolt11Exception
from bolt11 import decode as bolt11_decode
- from breez_sdk import (
+ from breez_sdk import ( # type: ignore[reportMissingImports]
BreezEvent,
ConnectRequest,
EnvironmentType,
@@ -39,7 +39,9 @@ else:
default_config,
mnemonic_to_seed,
)
- from breez_sdk import PaymentStatus as BreezPaymentStatus
+ from breez_sdk import (
+ PaymentStatus as BreezPaymentStatus, # type: ignore[reportMissingImports]
+ )
from loguru import logger
from lnbits.settings import settings
diff --git a/lnbits/wallets/breez_liquid.py b/lnbits/wallets/breez_liquid.py
index 6f1f6fb..c2a649a 100644
--- a/lnbits/wallets/breez_liquid.py
+++ b/lnbits/wallets/breez_liquid.py
@@ -18,7 +18,7 @@ else:
from pathlib import Path
from bolt11 import decode as bolt11_decode
- from breez_sdk_liquid import (
+ from breez_sdk_liquid import ( # type: ignore[reportMissingImports]
ConnectRequest,
EventListener,
GetInfoResponse,
diff --git a/lnbits/wallets/fake.py b/lnbits/wallets/fake.py
index be70d57..438c840 100644
--- a/lnbits/wallets/fake.py
+++ b/lnbits/wallets/fake.py
@@ -103,7 +103,7 @@ class FakeWallet(Wallet):
preimage=preimage.hex(),
)
- async def pay_invoice(self, bolt11: str, _: int) -> PaymentResponse:
+ async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse:
try:
invoice = decode(bolt11)
except Bolt11Exception as exc:
@@ -130,7 +130,7 @@ class FakeWallet(Wallet):
return PaymentPendingStatus()
return PaymentFailedStatus()
- async def get_payment_status(self, _: str) -> PaymentStatus:
+ async def get_payment_status(self, checking_id: str) -> PaymentStatus:
return PaymentPendingStatus()
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
diff --git a/lnbits/wallets/lndgrpc.py b/lnbits/wallets/lndgrpc.py
index 878433e..bef9415 100644
--- a/lnbits/wallets/lndgrpc.py
+++ b/lnbits/wallets/lndgrpc.py
@@ -118,7 +118,7 @@ class LndWallet(Wallet):
cert = open(cert_path, "rb").read()
creds = grpc.ssl_channel_credentials(cert)
- auth_creds = grpc.metadata_call_credentials(self.metadata_callback)
+ auth_creds = grpc.metadata_call_credentials(self.metadata_callback) # type: ignore[reportArgumentType]
composite_creds = grpc.composite_channel_credentials(creds, auth_creds)
channel = grpc.aio.secure_channel(
f"{self.endpoint}:{self.port}", composite_creds
diff --git a/package-lock.json b/package-lock.json
index 5040262..7291a74 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -24,7 +24,7 @@
"clean-css-cli": "^5.6.3",
"concat": "^1.0.3",
"prettier": "^3.8.3",
- "pyright": "1.1.289",
+ "pyright": "1.1.409",
"sass": "^1.99.0",
"terser": "^5.47.1"
}
@@ -1808,9 +1808,9 @@
}
},
"node_modules/pyright": {
- "version": "1.1.289",
- "resolved": "https://registry.npmjs.org/pyright/-/pyright-1.1.289.tgz",
- "integrity": "sha512-fG3STxnwAt3i7bxbXUPJdYNFrcOWHLwCSEOySH2foUqtYdzWLcxDez0Kgl1X8LMQx0arMJ6HRkKghxfRD1/z6g==",
+ "version": "1.1.409",
+ "resolved": "https://registry.npmjs.org/pyright/-/pyright-1.1.409.tgz",
+ "integrity": "sha512-13VFQyw4mJzshZxcxiYbNjo1hG/WHSRDj70Y3lbJEHqCkI2dvBAUTti8VV6Ezsr5gT93pFvC0e/jAQS4JdHarA==",
"dev": true,
"license": "MIT",
"bin": {
@@ -1818,7 +1818,10 @@
"pyright-langserver": "langserver.index.js"
},
"engines": {
- "node": ">=12.0.0"
+ "node": ">=14.0.0"
+ },
+ "optionalDependencies": {
+ "fsevents": "~2.3.3"
}
},
"node_modules/qrcode.vue": {
diff --git a/package.json b/package.json
index 9dfa1c7..105e42d 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,7 @@
"clean-css-cli": "^5.6.3",
"concat": "^1.0.3",
"prettier": "^3.8.3",
- "pyright": "1.1.289",
+ "pyright": "1.1.409",
"sass": "^1.99.0",
"terser": "^5.47.1"
},
diff --git a/tests/api/test_lnurl_api.py b/tests/api/test_lnurl_api.py
index 5cbdba4..80dc635 100644
--- a/tests/api/test_lnurl_api.py
+++ b/tests/api/test_lnurl_api.py
@@ -1,3 +1,4 @@
+from typing import cast
from uuid import uuid4
import pytest
@@ -106,7 +107,7 @@ async def test_lnurl_api_auth_and_pay_flow(mocker):
await api_perform_lnurlauth(auth_response, wallet_info)
action_response = LnurlPayActionResponse(
- pr=LightningInvoice(TEST_BOLT11),
+ pr=cast(LightningInvoice, LightningInvoice(TEST_BOLT11)),
disposable=False,
successAction=parse_obj_as(MessageAction, {"message": "paid"}),
)
diff --git a/tests/api/test_payment_api.py b/tests/api/test_payment_api.py
index 3e01020..95339b2 100644
--- a/tests/api/test_payment_api.py
+++ b/tests/api/test_payment_api.py
@@ -161,7 +161,7 @@ async def test_payment_api_fee_reserve_and_hold_invoice_actions(mocker):
wallet.id, CreateInvoice(out=False, amount=42, memo="reserve")
)
reserve = await api_payments_fee_reserve(invoice.bolt11)
- assert json.loads(reserve.body)["fee_reserve"] >= 0
+ assert json.loads(bytes(reserve.body))["fee_reserve"] >= 0
with pytest.raises(HTTPException, match="Invoice has no amount."):
await api_payments_fee_reserve(ZERO_AMOUNT_INVOICE)
diff --git a/tests/unit/test_services_lnurl.py b/tests/unit/test_services_lnurl.py
index 4145da6..d07a45a 100644
--- a/tests/unit/test_services_lnurl.py
+++ b/tests/unit/test_services_lnurl.py
@@ -1,3 +1,4 @@
+from typing import cast
from uuid import uuid4
import pytest
@@ -86,7 +87,9 @@ async def test_get_pr_from_lnurl_success_and_error(mocker: MockerFixture):
mocker.patch(
"lnbits.core.services.lnurl.execute_pay_request",
mocker.AsyncMock(
- return_value=LnurlPayActionResponse(pr=LightningInvoice(TEST_BOLT11))
+ return_value=LnurlPayActionResponse(
+ pr=cast(LightningInvoice, LightningInvoice(TEST_BOLT11))
+ )
),
)
@@ -106,7 +109,7 @@ async def test_fetch_lnurl_pay_request_converts_currency_and_stores_paylink(
):
pay_response = make_lnurl_pay_response(min_sendable_msat=1, text="Test")
action_response = LnurlPayActionResponse(
- pr=LightningInvoice(TEST_BOLT11), disposable=False
+ pr=cast(LightningInvoice, LightningInvoice(TEST_BOLT11)), disposable=False
)
mocker.patch(
"lnbits.core.services.lnurl.fiat_amount_as_satoshis",
@@ -143,7 +146,7 @@ async def test_store_paylink_appends_and_updates_existing():
wallet = await _create_wallet()
pay_response = make_lnurl_pay_response(min_sendable_msat=1, text="Test")
action_response = LnurlPayActionResponse(
- pr=LightningInvoice(TEST_BOLT11), disposable=False
+ pr=cast(LightningInvoice, LightningInvoice(TEST_BOLT11)), disposable=False
)
await store_paylink(
diff --git a/tests/unit/test_services_users.py b/tests/unit/test_services_users.py
index be16d3c..0e656c5 100644
--- a/tests/unit/test_services_users.py
+++ b/tests/unit/test_services_users.py
@@ -1,3 +1,4 @@
+from typing import Any
from uuid import uuid4
import pytest
@@ -66,7 +67,7 @@ async def test_create_user_account_no_check_rejects_duplicate_identity_fields(
existing = _account(**existing_data)
await create_account(existing)
- resolved = {
+ resolved: dict[str, Any] = {
key: (value(existing) if callable(value) else value)
for key, value in new_data.items()
}
diff --git a/tests/unit/test_settings.py b/tests/unit/test_settings.py
index bc34d15..d1fecc8 100644
--- a/tests/unit/test_settings.py
+++ b/tests/unit/test_settings.py
@@ -1,3 +1,5 @@
+from typing import Any
+
import pytest
from pytest_mock.plugin import MockerFixture
@@ -14,22 +16,22 @@ from lnbits.settings import (
set_cli_settings,
)
-lnurlp_redirect_path = {
+lnurlp_redirect_path: dict[str, Any] = {
"from_path": "/.well-known/lnurlp",
"redirect_to_path": "/api/v1/well-known",
}
-lnurlp_redirect_path_with_headers = {
+lnurlp_redirect_path_with_headers: dict[str, Any] = {
"from_path": "/.well-known/lnurlp",
"redirect_to_path": "/api/v1/well-known",
"header_filters": {"accept": "application/nostr+json"},
}
-lnaddress_redirect_path = {
+lnaddress_redirect_path: dict[str, Any] = {
"from_path": "/.well-known/lnurlp",
"redirect_to_path": "/api/v1/well-known",
}
-nostrrelay_redirect_path = {
+nostrrelay_redirect_path: dict[str, Any] = {
"from_path": "/",
"redirect_to_path": "/api/v1/relay-info",
"header_filters": {"accept": "application/nostr+json"},
diff --git a/tests/wallets/test_blink.py b/tests/wallets/test_blink.py
index b07271a..8a6ae65 100644
--- a/tests/wallets/test_blink.py
+++ b/tests/wallets/test_blink.py
@@ -1,4 +1,5 @@
import os
+from typing import cast
import pytest
from loguru import logger
@@ -29,7 +30,7 @@ logger.info(f"settings.blink_api_endpoint: {settings.blink_api_endpoint}")
logger.info(f"settings.blink_token: {settings.blink_token}")
set_funding_source()
-funding_source = get_funding_source()
+funding_source = cast(BlinkWallet, get_funding_source())
assert isinstance(funding_source, BlinkWallet)
diff --git a/tests/wallets/test_rpc_wallets.py b/tests/wallets/test_rpc_wallets.py
index e76c82c..51c3810 100644
--- a/tests/wallets/test_rpc_wallets.py
+++ b/tests/wallets/test_rpc_wallets.py
@@ -1,4 +1,5 @@
import importlib
+from typing import Any
from unittest.mock import AsyncMock, Mock
import pytest
@@ -80,7 +81,9 @@ def _check_calls(expected_calls):
for func_call in func_calls:
req = func_call["request_data"]
args = req["args"] if "args" in req else {}
- kwargs = _eval_dict(req["kwargs"]) if "kwargs" in req else {}
+ kwargs: dict[str, Any] = (
+ _eval_dict(req["kwargs"]) or {} if "kwargs" in req else {}
+ )
if "klass" in req:
*rest, cls = req["klass"].split(".")
@@ -166,7 +169,7 @@ def _mock_field(field):
return response
-def _eval_dict(data: dict | None) -> dict | None:
+def _eval_dict(data: dict | None) -> dict[str, Any] | None:
fn_prefix = "__eval__:"
if not data:
return data
@@ -215,9 +218,9 @@ def _data_mock(data: dict) -> Mock:
def _raise(error: dict | None):
if not error:
return Exception()
- data = error["data"] if "data" in error else None
+ data: dict[str, Any] = error["data"] if "data" in error else {}
if "module" not in error or "class" not in error:
- return Exception(data)
+ return Exception(data or None)
error_module = importlib.import_module(error["module"])
error_class = getattr(error_module, error["class"])
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.