From 25f0763f94993b5562c1ba83fa00df390f12d112 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 24 Sep 2024 13:53:35 +0200 Subject: [PATCH] chore: run pyupgrade (#623) - use `{...}` instead of `set([...])` - do not use `class Foo(object):`, just use `class Foo:` - do not specify default flags (`"r"`) for `open()` --- cashu/core/base.py | 6 +++--- cashu/core/helpers.py | 2 +- cashu/lightning/blink.py | 2 +- cashu/lightning/clnrest.py | 4 ++-- cashu/lightning/corelightningrest.py | 2 +- cashu/lightning/fake.py | 4 ++-- cashu/lightning/lnbits.py | 2 +- cashu/lightning/lnd_grpc/lnd_grpc.py | 2 +- cashu/lightning/lndrest.py | 2 +- cashu/mint/conditions.py | 2 +- cashu/mint/verification.py | 2 +- cashu/nostr/client/cbc.py | 2 +- cashu/nostr/filter.py | 2 +- cashu/tor/tor.py | 2 +- cashu/wallet/proofs.py | 8 ++++---- cashu/wallet/v1_api.py | 2 +- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cashu/core/base.py b/cashu/core/base.py index cf50f700..7f9ccee4 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -839,7 +839,7 @@ def amount(self) -> int: @property def keysets(self) -> List[str]: - return list(set([p.id for p in self.proofs])) + return list({p.id for p in self.proofs}) @property def mint(self) -> str: @@ -847,7 +847,7 @@ def mint(self) -> str: @property def mints(self) -> List[str]: - return list(set([t.mint for t in self.token if t.mint])) + return list({t.mint for t in self.token if t.mint}) @property def memo(self) -> Optional[str]: @@ -1037,7 +1037,7 @@ def proofs(self) -> List[Proof]: @property def keysets(self) -> List[str]: - return list(set([p.i.hex() for p in self.t])) + return list({p.i.hex() for p in self.t}) @classmethod def from_tokenv3(cls, tokenv3: TokenV3): diff --git a/cashu/core/helpers.py b/cashu/core/helpers.py index f3f3f0ff..80a6eccd 100644 --- a/cashu/core/helpers.py +++ b/cashu/core/helpers.py @@ -10,7 +10,7 @@ def amount_summary(proofs: List[Proof], unit: Unit) -> str: amounts_we_have = [ (amount, len([p for p in proofs if p.amount == amount])) - for amount in set([p.amount for p in proofs]) + for amount in {p.amount for p in proofs} ] amounts_we_have.sort(key=lambda x: x[0]) return ( diff --git a/cashu/lightning/blink.py b/cashu/lightning/blink.py index 1acb8a51..3f05130a 100644 --- a/cashu/lightning/blink.py +++ b/cashu/lightning/blink.py @@ -46,7 +46,7 @@ class BlinkWallet(LightningBackend): } payment_statuses = {"SUCCESS": True, "PENDING": None, "FAILURE": False} - supported_units = set([Unit.sat, Unit.msat]) + supported_units = {Unit.sat, Unit.msat} supports_description: bool = True unit = Unit.sat diff --git a/cashu/lightning/clnrest.py b/cashu/lightning/clnrest.py index 0dcb68eb..4a337687 100644 --- a/cashu/lightning/clnrest.py +++ b/cashu/lightning/clnrest.py @@ -27,7 +27,7 @@ class CLNRestWallet(LightningBackend): - supported_units = set([Unit.sat, Unit.msat]) + supported_units = {Unit.sat, Unit.msat} unit = Unit.sat supports_mpp = settings.mint_clnrest_enable_mpp supports_incoming_payment_stream: bool = True @@ -41,7 +41,7 @@ def __init__(self, unit: Unit = Unit.sat, **kwargs): raise Exception("missing rune for clnrest") # load from file or use as is if os.path.exists(rune_settings): - with open(rune_settings, "r") as f: + with open(rune_settings) as f: rune = f.read() rune = rune.strip() else: diff --git a/cashu/lightning/corelightningrest.py b/cashu/lightning/corelightningrest.py index 51a1ac23..58b462b3 100644 --- a/cashu/lightning/corelightningrest.py +++ b/cashu/lightning/corelightningrest.py @@ -27,7 +27,7 @@ class CoreLightningRestWallet(LightningBackend): - supported_units = set([Unit.sat, Unit.msat]) + supported_units = {Unit.sat, Unit.msat} unit = Unit.sat supports_incoming_payment_stream: bool = True supports_description: bool = True diff --git a/cashu/lightning/fake.py b/cashu/lightning/fake.py index b9d3cb39..18a3e6ff 100644 --- a/cashu/lightning/fake.py +++ b/cashu/lightning/fake.py @@ -39,12 +39,12 @@ class FakeWallet(LightningBackend): privkey: str = hashlib.pbkdf2_hmac( "sha256", secret.encode(), - ("FakeWallet").encode(), + b"FakeWallet", 2048, 32, ).hex() - supported_units = set([Unit.sat, Unit.msat, Unit.usd, Unit.eur]) + supported_units = {Unit.sat, Unit.msat, Unit.usd, Unit.eur} unit = Unit.sat supports_incoming_payment_stream: bool = True diff --git a/cashu/lightning/lnbits.py b/cashu/lightning/lnbits.py index 7daff1fe..14aa6ee6 100644 --- a/cashu/lightning/lnbits.py +++ b/cashu/lightning/lnbits.py @@ -25,7 +25,7 @@ class LNbitsWallet(LightningBackend): """https://github.com/lnbits/lnbits""" - supported_units = set([Unit.sat]) + supported_units = {Unit.sat} unit = Unit.sat supports_incoming_payment_stream: bool = True supports_description: bool = True diff --git a/cashu/lightning/lnd_grpc/lnd_grpc.py b/cashu/lightning/lnd_grpc/lnd_grpc.py index fa667ee0..7f7cecc9 100644 --- a/cashu/lightning/lnd_grpc/lnd_grpc.py +++ b/cashu/lightning/lnd_grpc/lnd_grpc.py @@ -49,7 +49,7 @@ class LndRPCWallet(LightningBackend): supports_mpp = settings.mint_lnd_enable_mpp supports_incoming_payment_stream = True - supported_units = set([Unit.sat, Unit.msat]) + supported_units = {Unit.sat, Unit.msat} supports_description: bool = True unit = Unit.sat diff --git a/cashu/lightning/lndrest.py b/cashu/lightning/lndrest.py index 18dbcd49..6bca1501 100644 --- a/cashu/lightning/lndrest.py +++ b/cashu/lightning/lndrest.py @@ -32,7 +32,7 @@ class LndRestWallet(LightningBackend): supports_mpp = settings.mint_lnd_enable_mpp supports_incoming_payment_stream = True - supported_units = set([Unit.sat, Unit.msat]) + supported_units = {Unit.sat, Unit.msat} supports_description: bool = True unit = Unit.sat diff --git a/cashu/mint/conditions.py b/cashu/mint/conditions.py index 983b1935..2f1f0cb7 100644 --- a/cashu/mint/conditions.py +++ b/cashu/mint/conditions.py @@ -274,7 +274,7 @@ def _verify_output_p2pk_spending_conditions( # all pubkeys and n_sigs must be the same assert ( - len(set([tuple(pubs_output) for pubs_output in pubkeys_per_proof])) == 1 + len({tuple(pubs_output) for pubs_output in pubkeys_per_proof}) == 1 ), "pubkeys in all proofs must match." assert len(set(n_sigs_per_proof)) == 1, "n_sigs in all proofs must match." diff --git a/cashu/mint/verification.py b/cashu/mint/verification.py index 429d2ee3..5521d64f 100644 --- a/cashu/mint/verification.py +++ b/cashu/mint/verification.py @@ -234,7 +234,7 @@ def _verify_units_match( return units_proofs[0] def get_fees_for_proofs(self, proofs: List[Proof]) -> int: - if not len(set([self.keysets[p.id].unit for p in proofs])) == 1: + if not len({self.keysets[p.id].unit for p in proofs}) == 1: raise TransactionUnitError("inputs have different units.") fee = (sum([self.keysets[p.id].input_fee_ppk for p in proofs]) + 999) // 1000 return fee diff --git a/cashu/nostr/client/cbc.py b/cashu/nostr/client/cbc.py index e69e8b5b..d0a92fbc 100644 --- a/cashu/nostr/client/cbc.py +++ b/cashu/nostr/client/cbc.py @@ -11,7 +11,7 @@ BLOCK_SIZE = 16 -class AESCipher(object): +class AESCipher: """This class is compatible with crypto.createCipheriv('aes-256-cbc')""" def __init__(self, key=None): diff --git a/cashu/nostr/filter.py b/cashu/nostr/filter.py index f119079c..78049756 100644 --- a/cashu/nostr/filter.py +++ b/cashu/nostr/filter.py @@ -76,7 +76,7 @@ def matches(self, event: Event) -> bool: return False if self.tags: - e_tag_identifiers = set([e_tag[0] for e_tag in event.tags]) + e_tag_identifiers = {e_tag[0] for e_tag in event.tags} for f_tag, f_tag_values in self.tags.items(): # Omit any NIP-01 or NIP-12 "#" chars on single-letter tags f_tag = f_tag.replace("#", "") diff --git a/cashu/tor/tor.py b/cashu/tor/tor.py index 114441c1..b4f9193d 100755 --- a/cashu/tor/tor.py +++ b/cashu/tor/tor.py @@ -144,7 +144,7 @@ def is_port_open(self): def read_pid(self): if not os.path.isfile(self.pid_file): return None - with open(self.pid_file, "r") as f: + with open(self.pid_file) as f: pid = f.readlines() # check if pid is valid if len(pid) == 0 or not int(pid[0]) > 0: diff --git a/cashu/wallet/proofs.py b/cashu/wallet/proofs.py index c0169e18..6172097f 100644 --- a/cashu/wallet/proofs.py +++ b/cashu/wallet/proofs.py @@ -34,7 +34,7 @@ async def _get_proofs_per_minturl( self, proofs: List[Proof], unit: Optional[Unit] = None ) -> Dict[str, List[Proof]]: ret: Dict[str, List[Proof]] = {} - keyset_ids = set([p.id for p in proofs]) + keyset_ids = {p.id for p in proofs} for id in keyset_ids: if id is None: continue @@ -178,7 +178,7 @@ async def _make_tokenv3( if not keysets: raise ValueError("No keysets found for proofs") assert ( - len(set([k.unit for k in keysets.values()])) == 1 + len({k.unit for k in keysets.values()}) == 1 ), "All keysets must have the same unit" unit = keysets[list(keysets.keys())[0]].unit @@ -216,14 +216,14 @@ async def _make_tokenv4( except KeyError: raise ValueError("Keysets of proofs are not loaded in wallet") # we make sure that all proofs are from keysets of the same mint - if len(set([k.mint_url for k in keysets])) > 1: + if len({k.mint_url for k in keysets}) > 1: raise ValueError("TokenV4 can only contain proofs from a single mint URL") mint_url = keysets[0].mint_url if not mint_url: raise ValueError("No mint URL found for keyset") # we make sure that all keysets have the same unit - if len(set([k.unit for k in keysets])) > 1: + if len({k.unit for k in keysets}) > 1: raise ValueError( "TokenV4 can only contain proofs from keysets with the same unit" ) diff --git a/cashu/wallet/v1_api.py b/cashu/wallet/v1_api.py index f1a8bb16..5905391a 100644 --- a/cashu/wallet/v1_api.py +++ b/cashu/wallet/v1_api.py @@ -99,7 +99,7 @@ async def wrapper(self, *args, **kwargs): return wrapper -class LedgerAPI(LedgerAPIDeprecated, object): +class LedgerAPI(LedgerAPIDeprecated): tor: TorProxy db: Database # we need the db for melt_deprecated httpx: httpx.AsyncClient