diff --git a/lnbits/core/services.py b/lnbits/core/services.py index af5e6716c..950e3f321 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -214,20 +214,20 @@ async def pay_invoice( ) logger.debug(f"backend: pay_invoice finished {temp_id}") - if payment.checking_id and payment.ok != False: + if payment.checking_id and payment.ok is not False: # payment.ok can be True (paid) or None (pending)! logger.debug(f"updating payment {temp_id}") async with db.connect() as conn: await update_payment_details( checking_id=temp_id, - pending=payment.ok != True, + pending=payment.ok is not True, fee=payment.fee_msat, preimage=payment.preimage, new_checking_id=payment.checking_id, conn=conn, ) logger.debug(f"payment successful {payment.checking_id}") - elif payment.checking_id is None and payment.ok == False: + elif payment.checking_id is None and payment.ok is False: # payment failed logger.warning(f"backend sent payment failure") async with db.connect() as conn: diff --git a/lnbits/extension_manager.py b/lnbits/extension_manager.py index 7955c791d..8371aea9a 100644 --- a/lnbits/extension_manager.py +++ b/lnbits/extension_manager.py @@ -240,7 +240,7 @@ class InstallableExtension(BaseModel): return False with open(config_file, "r") as json_file: config_json = json.load(json_file) - return config_json.get("is_installed") == True + return config_json.get("is_installed") is True def download_archive(self): ext_zip_file = self.zip_path diff --git a/lnbits/extensions/cashu/views_api.py b/lnbits/extensions/cashu/views_api.py index 1b65a567a..d896cf713 100644 --- a/lnbits/extensions/cashu/views_api.py +++ b/lnbits/extensions/cashu/views_api.py @@ -335,7 +335,7 @@ async def melt_coins( status: PaymentStatus = await check_transaction_status( cashu.wallet, invoice_obj.payment_hash ) - if status.paid == True: + if status.paid is True: logger.debug( f"Cashu: Payment successful, invalidating proofs for {invoice_obj.payment_hash}" ) diff --git a/lnbits/extensions/events/views_api.py b/lnbits/extensions/events/views_api.py index 5ec9b916e..c21ccfa88 100644 --- a/lnbits/extensions/events/views_api.py +++ b/lnbits/extensions/events/views_api.py @@ -188,7 +188,7 @@ async def api_event_register_ticket(ticket_id): status_code=HTTPStatus.FORBIDDEN, detail="Ticket not paid for." ) - if ticket.registered == True: + if ticket.registered is True: raise HTTPException( status_code=HTTPStatus.FORBIDDEN, detail="Ticket already registered" ) diff --git a/lnbits/extensions/jukebox/views_api.py b/lnbits/extensions/jukebox/views_api.py index 0cca8fc85..8e0bdd27c 100644 --- a/lnbits/extensions/jukebox/views_api.py +++ b/lnbits/extensions/jukebox/views_api.py @@ -123,7 +123,7 @@ async def api_get_jukebox_song( if "items" not in r.json(): if r.status_code == 401: token = await api_get_token(juke_id) - if token == False: + if token is False: return False elif retry: raise HTTPException( @@ -205,7 +205,7 @@ async def api_get_jukebox_device_check( return json.loads(rDevice.text) elif rDevice.status_code == 401 or rDevice.status_code == 403: token = await api_get_token(juke_id) - if token == False: + if token is False: raise HTTPException( status_code=HTTPStatus.FORBIDDEN, detail="No devices connected" ) @@ -309,7 +309,7 @@ async def api_get_jukebox_invoice_paid( if rDevice.status_code == 200: isPlaying = rDevice.json()["is_playing"] - if r.status_code == 204 or isPlaying == False: + if r.status_code == 204 or isPlaying is False: async with httpx.AsyncClient() as client: uri = ["spotify:track:" + song_id] assert jukebox.sp_device @@ -324,7 +324,7 @@ async def api_get_jukebox_invoice_paid( return jukebox_payment elif r.status_code == 401 or r.status_code == 403: token = await api_get_token(juke_id) - if token == False: + if token is False: raise HTTPException( status_code=HTTPStatus.FORBIDDEN, detail="Invoice not paid", @@ -359,7 +359,7 @@ async def api_get_jukebox_invoice_paid( elif r.status_code == 401 or r.status_code == 403: token = await api_get_token(juke_id) - if token == False: + if token is False: raise HTTPException( status_code=HTTPStatus.FORBIDDEN, detail="Invoice not paid", @@ -379,7 +379,7 @@ async def api_get_jukebox_invoice_paid( ) elif r.status_code == 401 or r.status_code == 403: token = await api_get_token(juke_id) - if token == False: + if token is False: raise HTTPException( status_code=HTTPStatus.OK, detail="Invoice not paid" ) @@ -433,7 +433,7 @@ async def api_get_jukebox_currently( elif r.status_code == 401: token = await api_get_token(juke_id) - if token == False: + if token is False: raise HTTPException( status_code=HTTPStatus.FORBIDDEN, detail="Invoice not paid" ) diff --git a/lnbits/extensions/lnaddress/crud.py b/lnbits/extensions/lnaddress/crud.py index 0e590ec8d..a0201ee64 100644 --- a/lnbits/extensions/lnaddress/crud.py +++ b/lnbits/extensions/lnaddress/crud.py @@ -130,7 +130,7 @@ async def set_address_paid(payment_hash: str) -> Addresses: address = await get_address(payment_hash) assert address - if address.paid == False: + if address.paid is False: await db.execute( """ UPDATE lnaddress.address diff --git a/lnbits/extensions/nostrnip5/views_api.py b/lnbits/extensions/nostrnip5/views_api.py index 99a0fe011..aa5dc887b 100644 --- a/lnbits/extensions/nostrnip5/views_api.py +++ b/lnbits/extensions/nostrnip5/views_api.py @@ -270,7 +270,7 @@ async def api_get_nostr_json( if not local_part: continue - if address.get("active") == False: + if address.get("active") is False: continue if name and name.lower() != local_part.lower(): diff --git a/lnbits/extensions/satspay/models.py b/lnbits/extensions/satspay/models.py index 0b2b14739..c9da401a2 100644 --- a/lnbits/extensions/satspay/models.py +++ b/lnbits/extensions/satspay/models.py @@ -77,7 +77,7 @@ class Charges(BaseModel): return ChargeConfig(**charge_config) def must_call_webhook(self): - return self.webhook and self.paid and self.config.webhook_success == False + return self.webhook and self.paid and self.config.webhook_success is False class SatsPayThemes(BaseModel): diff --git a/lnbits/extensions/smtp/crud.py b/lnbits/extensions/smtp/crud.py index c7b96df59..5dc384dc0 100644 --- a/lnbits/extensions/smtp/crud.py +++ b/lnbits/extensions/smtp/crud.py @@ -121,7 +121,7 @@ async def create_email(wallet: str, data: CreateEmail, payment_hash: str = "") - async def set_email_paid(payment_hash: str) -> bool: email = await get_email_by_payment_hash(payment_hash) - if email and email.paid == False: + if email and email.paid is False: await db.execute( f"UPDATE smtp.email SET paid = true WHERE payment_hash = ?", (payment_hash,) ) diff --git a/lnbits/extensions/subdomains/crud.py b/lnbits/extensions/subdomains/crud.py index aa358d11c..b3476ed93 100644 --- a/lnbits/extensions/subdomains/crud.py +++ b/lnbits/extensions/subdomains/crud.py @@ -36,7 +36,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains: "SELECT s.*, d.domain as domain_name FROM subdomains.subdomain s INNER JOIN subdomains.domain d ON (s.domain = d.id) WHERE s.id = ?", (payment_hash,), ) - if row[8] == False: + if row[8] is False: await db.execute( """ UPDATE subdomains.subdomain diff --git a/lnbits/extensions/subdomains/views_api.py b/lnbits/extensions/subdomains/views_api.py index 9fbae4f3a..6f85c66e0 100644 --- a/lnbits/extensions/subdomains/views_api.py +++ b/lnbits/extensions/subdomains/views_api.py @@ -128,7 +128,7 @@ async def api_subdomain_make_subdomain(domain_id, data: CreateSubdomain): record_type=data.record_type, ip=data.ip, ) - if cf_response["success"] == True: + if cf_response["success"] is True: await cloudflare_deletesubdomain( domain=domain, domain_id=cf_response["result"]["id"] ) diff --git a/lnbits/wallets/base.py b/lnbits/wallets/base.py index e38b6d8fc..ecc6892e8 100644 --- a/lnbits/wallets/base.py +++ b/lnbits/wallets/base.py @@ -34,12 +34,12 @@ class PaymentStatus(NamedTuple): @property def failed(self) -> bool: - return self.paid == False + return self.paid is False def __str__(self) -> str: - if self.paid == True: + if self.paid is True: return "settled" - elif self.paid == False: + elif self.paid is False: return "failed" elif self.paid == None: return "still pending" diff --git a/lnbits/wallets/lndgrpc.py b/lnbits/wallets/lndgrpc.py index 25b04ed34..b34368b1b 100644 --- a/lnbits/wallets/lndgrpc.py +++ b/lnbits/wallets/lndgrpc.py @@ -216,11 +216,11 @@ class LndWallet(Wallet): error_message = None checking_id = None - if statuses[resp.status] == True: # SUCCEEDED + if statuses[resp.status] is True: # SUCCEEDED fee_msat = -resp.htlcs[-1].route.total_fees_msat preimage = resp.payment_preimage checking_id = resp.payment_hash - elif statuses[resp.status] == False: + elif statuses[resp.status] is False: error_message = failure_reasons[resp.failure_reason] return PaymentResponse( diff --git a/tests/core/views/test_api.py b/tests/core/views/test_api.py index dbc1c1298..caced159c 100644 --- a/tests/core/views/test_api.py +++ b/tests/core/views/test_api.py @@ -127,7 +127,7 @@ async def test_check_payment_without_key(client, invoice): # check the payment status response = await client.get(f"/api/v1/payments/{invoice['payment_hash']}") assert response.status_code < 300 - assert response.json()["paid"] == True + assert response.json()["paid"] is True assert invoice # not key, that's why no "details" assert "details" not in response.json() @@ -145,7 +145,7 @@ async def test_check_payment_with_key(client, invoice, inkey_headers_from): f"/api/v1/payments/{invoice['payment_hash']}", headers=inkey_headers_from ) assert response.status_code < 300 - assert response.json()["paid"] == True + assert response.json()["paid"] is True assert invoice # with key, that's why with "details" assert "details" in response.json() @@ -205,7 +205,7 @@ async def test_api_payment_without_key(invoice): # check the payment status response = await api_payment(invoice["payment_hash"]) assert type(response) == dict - assert response["paid"] == True + assert response["paid"] is True # no key, that's why no "details" assert "details" not in response @@ -218,7 +218,7 @@ async def test_api_payment_with_key(invoice, inkey_headers_from): invoice["payment_hash"], inkey_headers_from["X-Api-Key"] ) assert type(response) == dict - assert response["paid"] == True + assert response["paid"] is True assert "details" in response diff --git a/tests/extensions/bleskomat/test_lnurl_api.py b/tests/extensions/bleskomat/test_lnurl_api.py index ec4a26dad..dab0fb98c 100644 --- a/tests/extensions/bleskomat/test_lnurl_api.py +++ b/tests/extensions/bleskomat/test_lnurl_api.py @@ -115,7 +115,7 @@ async def test_bleskomat_lnurl_api_action_insufficient_balance(client, lnurl): assert wallet.balance_msat == 0 bleskomat_lnurl = await get_bleskomat_lnurl(secret) assert bleskomat_lnurl, not None - assert bleskomat_lnurl.has_uses_remaining() == True + assert bleskomat_lnurl.has_uses_remaining() is True WALLET.pay_invoice.assert_not_called() @@ -140,5 +140,5 @@ async def test_bleskomat_lnurl_api_action_success(client, lnurl): assert wallet.balance_msat == 50000 bleskomat_lnurl = await get_bleskomat_lnurl(secret) assert bleskomat_lnurl, not None - assert bleskomat_lnurl.has_uses_remaining() == False + assert bleskomat_lnurl.has_uses_remaining() is False WALLET.pay_invoice.assert_called_once_with(pr, 2000) diff --git a/tests/extensions/invoices/test_invoices_api.py b/tests/extensions/invoices/test_invoices_api.py index ed236a8fd..5b7155f54 100644 --- a/tests/extensions/invoices/test_invoices_api.py +++ b/tests/extensions/invoices/test_invoices_api.py @@ -80,7 +80,7 @@ async def test_invoices_api_partial_pay_invoice( f"/invoices/api/v1/invoice/{invoice_id}/payments/{payment_hash}" ) assert response.status_code == 200 - assert response.json()["paid"] == True + assert response.json()["paid"] is True # check invoice status response = await client.get(f"/invoices/api/v1/invoice/{invoice_id}") @@ -124,7 +124,7 @@ async def test_invoices_api_partial_pay_invoice( # f"/invoices/api/v1/invoice/{invoice_id}/payments/{payment_hash}" # ) # assert response.status_code == 200 -# assert response.json()["paid"] == True +# assert response.json()["paid"] is True # # check invoice status # response = await client.get(f"/invoices/api/v1/invoice/{invoice_id}")