Skip to content

Commit

Permalink
chore: run pyupgrade (#623)
Browse files Browse the repository at this point in the history
- use `{...}` instead of `set([...])`
- do not use `class Foo(object):`, just use `class Foo:`
- do not specify default flags (`"r"`) for `open()`
  • Loading branch information
prusnak authored Sep 24, 2024
1 parent 870d75b commit 25f0763
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,15 +839,15 @@ 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:
return self.mints[0]

@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]:
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion cashu/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion cashu/lightning/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions cashu/lightning/clnrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cashu/lightning/corelightningrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cashu/lightning/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cashu/lightning/lnbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cashu/lightning/lnd_grpc/lnd_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cashu/lightning/lndrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cashu/mint/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down
2 changes: 1 addition & 1 deletion cashu/mint/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cashu/nostr/client/cbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion cashu/nostr/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("#", "")
Expand Down
2 changes: 1 addition & 1 deletion cashu/tor/tor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions cashu/wallet/proofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion cashu/wallet/v1_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 25f0763

Please sign in to comment.