From a0cc55c5a10f1a2ca41e4539a11176d514c430d8 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sat, 21 Jan 2023 12:38:17 +0000 Subject: [PATCH] fix pylint C0209 (consider-using-f-string) --- lnbits/app.py | 2 +- lnbits/bolt11.py | 28 +++++++++++----------------- lnbits/wallets/cln.py | 4 ++-- lnbits/wallets/lndrest.py | 2 +- lnbits/wallets/spark.py | 2 +- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lnbits/app.py b/lnbits/app.py index ee3b07367..65d63e67b 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -388,7 +388,7 @@ class Formatter: self.fmt: str = self.minimal_fmt def format(self, record): - function = "{function}".format(**record) + function = "{function}".format(**record) # pylint: disable=C0209 if function == "emit": # uvicorn logs return self.minimal_fmt return self.fmt diff --git a/lnbits/bolt11.py b/lnbits/bolt11.py index 1da6ce2a9..a7224d887 100644 --- a/lnbits/bolt11.py +++ b/lnbits/bolt11.py @@ -166,9 +166,7 @@ def lnencode(addr, privkey): amount = Decimal(str(addr.amount)) # We can only send down to millisatoshi. if amount * 10**12 % 10: - raise ValueError( - "Cannot encode {}: too many decimal places".format(addr.amount) - ) + raise ValueError(f"Cannot encode {addr.amount}: too many decimal places") amount = addr.currency + shorten_amount(amount) else: @@ -190,7 +188,7 @@ def lnencode(addr, privkey): # A writer MUST NOT include more than one `d`, `h`, `n` or `x` fields, if k in ("d", "h", "n", "x"): if k in tags_set: - raise ValueError("Duplicate '{}' tag".format(k)) + raise ValueError(f"Duplicate '{k}' tag") if k == "r": route = bitstring.BitArray() @@ -220,7 +218,7 @@ def lnencode(addr, privkey): data += tagged_bytes("n", v) else: # FIXME: Support unknown tags? - raise ValueError("Unknown tag {}".format(k)) + raise ValueError(f"Unknown tag {k}") tags_set.add(k) @@ -259,12 +257,9 @@ class LnAddr: self.amount = amount def __str__(self): - return "LnAddr[{}, amount={}{} tags=[{}]]".format( - bytes.hex(self.pubkey.serialize()).decode(), - self.amount, - self.currency, - ", ".join([k + "=" + str(v) for k, v in self.tags]), - ) + pubkey = bytes.hex(self.pubkey.serialize()).decode() + tags = ", ".join([k + "=" + str(v) for k, v in self.tags]) + return f"LnAddr[{pubkey}, amount={self.amount}{self.currency} tags=[{tags}]]" def shorten_amount(amount): @@ -296,7 +291,7 @@ def _unshorten_amount(amount: str) -> int: # A reader SHOULD fail if `amount` contains a non-digit, or is followed by # anything except a `multiplier` in the table above. if not re.fullmatch(r"\d+[pnum]?", str(amount)): - raise ValueError("Invalid amount '{}'".format(amount)) + raise ValueError(f"Invalid amount '{amount}'") if unit in units: return int(int(amount[:-1]) * 100_000_000_000 / units[unit]) @@ -347,11 +342,10 @@ def _trim_to_bytes(barr): def _readable_scid(short_channel_id: int) -> str: - return "{blockheight}x{transactionindex}x{outputindex}".format( - blockheight=((short_channel_id >> 40) & 0xFFFFFF), - transactionindex=((short_channel_id >> 16) & 0xFFFFFF), - outputindex=(short_channel_id & 0xFFFF), - ) + blockheight = (short_channel_id >> 40) & 0xFFFFFF + transactionindex = (short_channel_id >> 16) & 0xFFFFFF + outputindex = short_channel_id & 0xFFFF + return f"{blockheight}x{transactionindex}x{outputindex}" def _u5_to_bitarray(arr: List[int]) -> bitstring.BitArray: diff --git a/lnbits/wallets/cln.py b/lnbits/wallets/cln.py index 2bd6b2149..642aef508 100644 --- a/lnbits/wallets/cln.py +++ b/lnbits/wallets/cln.py @@ -83,7 +83,7 @@ class CoreLightningWallet(Wallet): unhashed_description: Optional[bytes] = None, **kwargs, ) -> InvoiceResponse: - label = "lbl{}".format(random.random()) + label = f"lbl{random.random()}" msat: int = int(amount * 1000) try: if description_hash and not unhashed_description: @@ -126,7 +126,7 @@ class CoreLightningWallet(Wallet): payload = { "bolt11": bolt11, - "maxfeepercent": "{:.11}".format(fee_limit_percent), + "maxfeepercent": f"{fee_limit_percent:.11}", "exemptfee": 0, # so fee_limit_percent is applied even on payments with fee < 5000 millisatoshi (which is default value of exemptfee) } try: diff --git a/lnbits/wallets/lndrest.py b/lnbits/wallets/lndrest.py index d07aae097..0c9d5aed2 100644 --- a/lnbits/wallets/lndrest.py +++ b/lnbits/wallets/lndrest.py @@ -113,7 +113,7 @@ class LndRestWallet(Wallet): async with httpx.AsyncClient(verify=self.cert) as client: # set the fee limit for the payment lnrpcFeeLimit = dict() - lnrpcFeeLimit["fixed_msat"] = "{}".format(fee_limit_msat) + lnrpcFeeLimit["fixed_msat"] = f"{fee_limit_msat}" r = await client.post( url=f"{self.endpoint}/v1/channels/transactions", diff --git a/lnbits/wallets/spark.py b/lnbits/wallets/spark.py index 6f0f55db8..edfa01d02 100644 --- a/lnbits/wallets/spark.py +++ b/lnbits/wallets/spark.py @@ -97,7 +97,7 @@ class SparkWallet(Wallet): unhashed_description: Optional[bytes] = None, **kwargs, ) -> InvoiceResponse: - label = "lbs{}".format(random.random()) + label = f"lbs{random.random()}" checking_id = label try: