From 8e13b296fbbfedb11bb4ad83290e286c4ba48cd9 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 11 Oct 2023 12:58:48 +0000 Subject: [PATCH] pylint throughout (excluding tests) - string formatting --- mmgen/mn_entry.py | 8 ++--- mmgen/msg.py | 4 +-- mmgen/obj.py | 6 ++-- mmgen/passwdlist.py | 9 +++--- mmgen/proto/eth/tx/unsigned.py | 7 ++++- mmgen/tool/rpc.py | 2 +- mmgen/tw/prune.py | 4 ++- mmgen/tw/view.py | 12 ++++---- mmgen/tx/new.py | 16 +++++----- mmgen/wallet/incog_hidden.py | 14 ++++----- mmgen/xmrwallet.py | 56 +++++++++++++++++----------------- 11 files changed, 72 insertions(+), 66 deletions(-) diff --git a/mmgen/mn_entry.py b/mmgen/mn_entry.py index 3995d7d2..9cb507d0 100755 --- a/mmgen/mn_entry.py +++ b/mmgen/mn_entry.py @@ -392,11 +392,11 @@ class MnemonicEntry(object): for k,v in self.cfg.mnemonic_entry_modes.items(): cls = self.get_cls_by_wordlist(k) if v not in cls.entry_modes: - errmsg = """ + errmsg = f""" Error in cfg file option 'mnemonic_entry_modes': - Entry mode {!r} not recognized for wordlist {!r}: - Valid choices: {} - """.format( v, k, fmt_list(cls.entry_modes) ) + Entry mode {v!r} not recognized for wordlist {k!r}: + Valid choices: {fmt_list(cls.entry_modes)} + """ die(2, '\n' + fmt(errmsg,indent=' ')) if cls == type(self): self.usr_dfl_entry_mode = v diff --git a/mmgen/msg.py b/mmgen/msg.py index 6c4cbf54..45b9d639 100755 --- a/mmgen/msg.py +++ b/mmgen/msg.py @@ -212,9 +212,7 @@ class coin_msg: if req_addr: return '\n'.join(gen_single()) else: - return ( - '{}SIGNED MESSAGE DATA:\n\n '.format('' if self.sigs else 'UN') + - '\n '.join(gen_all()) ) + return ('' if self.sigs else 'UN') + 'SIGNED MESSAGE DATA:\n\n ' + '\n '.join(gen_all()) class unsigned(completed): diff --git a/mmgen/obj.py b/mmgen/obj.py index fc627d15..3f009329 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -365,8 +365,10 @@ class MMGenLabel(str,Hilite,InitErrors): # Disallow: (C)ontrol,(M)combining # Combining characters create width formatting issues, so disallow them for now if unicodedata.category(ch)[0] in ('C','M'): - raise ValueError('{!a}: {} characters not allowed'.format(ch, - { 'C':'control', 'M':'combining' }[unicodedata.category(ch)[0]] )) + raise ValueError( + '{!a}: {} characters not allowed'.format( + ch, + { 'C':'control', 'M':'combining' }[unicodedata.category(ch)[0]] )) me = str.__new__(cls,s) diff --git a/mmgen/passwdlist.py b/mmgen/passwdlist.py index 8b9a08a6..9fac2a92 100755 --- a/mmgen/passwdlist.py +++ b/mmgen/passwdlist.py @@ -185,11 +185,10 @@ class PasswordList(AddrList): if pw_bytes > seed.byte_len: die(1, - 'Cannot generate passwords with more entropy than underlying seed! ({} bits)\n'.format( - len(seed.data) * 8 ) + ( - 'Re-run the command with --passwd-len={}' if pf in ('bip39','hex') else - 'Re-run the command, specifying a password length of {} or less' - ).format(good_pw_len) ) + f'Cannot generate passwords with more entropy than underlying seed! ({len(seed.data)*8} bits)\n' + + (f'Re-run the command with --passwd-len={good_pw_len}' if pf in ('bip39','hex') else + 'Re-run the command, specifying a password length of {} or less') + ) if pf in ('bip39','hex') and pw_bytes < seed.byte_len: from .ui import keypress_confirm diff --git a/mmgen/proto/eth/tx/unsigned.py b/mmgen/proto/eth/tx/unsigned.py index a9705d22..afb071a1 100755 --- a/mmgen/proto/eth/tx/unsigned.py +++ b/mmgen/proto/eth/tx/unsigned.py @@ -100,5 +100,10 @@ class TokenUnsigned(TokenCompleted,Unsigned): async def do_sign(self,wif,tx_num_str): o = self.txobj t = Token(self.cfg,self.proto,o['token_addr'],o['decimals']) - tx_in = t.make_tx_in(o['from'],o['to'],o['amt'],self.start_gas,o['gasPrice'],nonce=o['nonce']) + tx_in = t.make_tx_in( + to_addr = o['to'], + amt = o['amt'], + start_gas = self.start_gas, + gasPrice = o['gasPrice'], + nonce = o['nonce']) (self.serialized,self.coin_txid) = await t.txsign(tx_in,wif,o['from'],chain_id=o['chainId']) diff --git a/mmgen/tool/rpc.py b/mmgen/tool/rpc.py index e9a1fb64..6ef5fa09 100755 --- a/mmgen/tool/rpc.py +++ b/mmgen/tool/rpc.py @@ -142,7 +142,7 @@ class tool_cmd(tool_cmd_base): all_labels: 'show all addresses with labels' = False ): "list MMGen addresses in the tracking wallet and their balances" - assert showused in (0,1,2), f"‘showused’ must have a value of 0, 1 or 2" + assert showused in (0,1,2), "‘showused’ must have a value of 0, 1 or 2" from ..tw.addresses import TwAddresses obj = await TwAddresses(self.cfg,self.proto,minconf=minconf,mmgen_addrs=mmgen_addrs) diff --git a/mmgen/tw/prune.py b/mmgen/tw/prune.py index 9f2ce467..1c5208d6 100755 --- a/mmgen/tw/prune.py +++ b/mmgen/tw/prune.py @@ -96,7 +96,9 @@ class TwAddressesPrune(TwAddresses): '[p]rune anyway, [P]rune all with balance, [s]kip, [S]kip all with balance: ', ), 'used': md( - yellow('Address #{} ({}) is used!'.format( addrnum, e.twmmid.addr )), + yellow('Address #{a} ({b}) is used!'.format( + a = addrnum, + b = e.twmmid.addr )), '[p]rune anyway, [P]rune all used, [s]kip, [S]kip all used: ', ), } diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index e002d6bc..4355b050 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -614,12 +614,12 @@ class TwView(MMGenObject,metaclass=AsyncInit): if not parent.disp_data: return None - outfile = '{}{}-{}{}[{}].out'.format( - parent.dump_fn_pfx, - f'-{output_type}' if len(parent.print_output_types) > 1 else '', - parent.proto.dcoin, - ('' if parent.proto.network == 'mainnet' else '-'+parent.proto.network.upper()), - ','.join(parent.sort_info(include_group=False)).replace(' ','') ) + outfile = '{a}{b}-{c}{d}[{e}].out'.format( + a = parent.dump_fn_pfx, + b = f'-{output_type}' if len(parent.print_output_types) > 1 else '', + c = parent.proto.dcoin, + d = ('' if parent.proto.network == 'mainnet' else '-'+parent.proto.network.upper()), + e = ','.join(parent.sort_info(include_group=False)).replace(' ','') ) print_hdr = getattr(parent.display_type,output_type).print_header.format(parent.cols) diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index 2ff7b117..4a9a141e 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -122,16 +122,16 @@ class New(Base): if fee: abs_fee = self.convert_and_check_fee(fee,desc) if abs_fee: - prompt = '{} TX fee{}: {}{} {} ({} {})\n'.format( - desc, - (f' (after {self.cfg.fee_adjust:.2f}X adjustment)' + prompt = '{a} TX fee{b}: {c}{d} {e} ({f} {g})\n'.format( + a = desc, + b = (f' (after {self.cfg.fee_adjust:.2f}X adjustment)' if self.cfg.fee_adjust != 1 and desc.startswith('Network-estimated') else ''), - ('','≈')[self.fee_is_approximate], - abs_fee.hl(), - self.coin, - pink(str(self.fee_abs2rel(abs_fee))), - self.rel_fee_disp) + c = ('','≈')[self.fee_is_approximate], + d = abs_fee.hl(), + e = self.coin, + f = pink(str(self.fee_abs2rel(abs_fee))), + g = self.rel_fee_disp) from ..ui import keypress_confirm if self.cfg.yes or keypress_confirm( self.cfg, prompt+'OK?', default_yes=True ): if self.cfg.yes: diff --git a/mmgen/wallet/incog_hidden.py b/mmgen/wallet/incog_hidden.py index 3d5d0c89..4993a086 100755 --- a/mmgen/wallet/incog_hidden.py +++ b/mmgen/wallet/incog_hidden.py @@ -55,13 +55,13 @@ class wallet(wallet): d = self.ssdata m = ('Input','Destination')[action=='write'] if fn.size < d.hincog_offset + d.target_data_len: - die(1,'{} file {!r} has length {}, too short to {} {} bytes of data at offset {}'.format( - m, - fn.name, - fn.size, - action, - d.target_data_len, - d.hincog_offset )) + die(1,'{a} file {b!r} has length {c}, too short to {d} {e} bytes of data at offset {f}'.format( + a = m, + b = fn.name, + c = fn.size, + d = action, + e = d.target_data_len, + f = d.hincog_offset )) def _get_data(self): d = self.ssdata diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index e2889ac4..593439b4 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -901,11 +901,11 @@ class MoneroWalletOps: processed = 0 for n,d in enumerate(self.addr_data): # [d.sec,d.addr,d.wallet_passwd,d.viewkey] fn = self.get_wallet_fn(d) - gmsg('\n{}ing wallet {}/{} ({})'.format( - self.stem.capitalize(), - n+1, - len(self.addr_data), - fn.name, + gmsg('\n{a}ing wallet {b}/{c} ({d})'.format( + a = self.stem.capitalize(), + b = n + 1, + c = len(self.addr_data), + d = fn.name, )) processed += await self.process_wallet( d, @@ -964,15 +964,15 @@ class MoneroWalletOps: def print_accts(self,data,addrs_data,indent=' '): d = data['subaddress_accounts'] msg('\n' + indent + f'Accounts of wallet {self.fn.name}:') - fs = indent + ' {:6} {:18} {:<6} {:%s} {}' % max(len(e['label']) for e in d) - msg(fs.format('Index ','Base Address','nAddrs','Label','Unlocked Balance')) + fs = indent + ' {a:6} {b:18} {c:<6} {d:%s} {e}' % max(len(e['label']) for e in d) + msg(fs.format(a='Index ',b='Base Address',c='nAddrs',d='Label',e='Unlocked Balance')) for i,e in enumerate(d): msg(fs.format( - str(e['account_index']), - e['base_address'][:15] + '...', - len(addrs_data[i]['addresses']), - e['label'], - fmt_amt(e['unlocked_balance']), + a = str(e['account_index']), + b = e['base_address'][:15] + '...', + c = len(addrs_data[i]['addresses']), + d = e['label'], + e = fmt_amt(e['unlocked_balance']), )) def get_accts(self,print=True): @@ -1353,12 +1353,12 @@ class MoneroWalletOps: fs = ' {:2} {} {} {}' msg('\n' + green(f'Wallet {k}:')) for acct_num,acct in enumerate(d[k]['addrs']): - msg('\n Account #{} [{} {}]'.format( - acct_num, - self.proto.coin_amt( + msg('\n Account #{a} [{b} {c}]'.format( + a = acct_num, + b = self.proto.coin_amt( d[k]['accts']['subaddress_accounts'][acct_num]['unlocked_balance'], from_unit='atomic').hl(), - self.proto.coin_amt.hlc('XMR') + c = self.proto.coin_amt.hlc('XMR') )) msg(fs.format('','Address'.ljust(95),'Used ','Label')) for addr in acct['addresses']: @@ -1582,11 +1582,11 @@ class MoneroWalletOps: async def main(self): - gmsg('\n{} label for wallet {}, account #{}, address #{}'.format( - 'Setting' if self.label else 'Removing', - self.source.idx, - self.account, - self.address_idx + gmsg('\n{a} label for wallet {b}, account #{c}, address #{d}'.format( + a = 'Setting' if self.label else 'Removing', + b = self.source.idx, + c = self.account, + d = self.address_idx )) h = self.rpc(self,self.source) @@ -1606,13 +1606,13 @@ class MoneroWalletOps: addr = ret['addresses'][self.address_idx] - msg('\n {} {}\n {} {}\n {} {}'.format( - 'Address: ', - cyan(addr['address'][:15] + '...'), - 'Existing label:', - pink(addr['label']) if addr['label'] else '[none]', - 'New label: ', - pink(self.label) if self.label else '[none]' )) + msg('\n {a} {b}\n {c} {d}\n {e} {f}'.format( + a = 'Address: ', + b = cyan(addr['address'][:15] + '...'), + c = 'Existing label:', + d = pink(addr['label']) if addr['label'] else '[none]', + e = 'New label: ', + f = pink(self.label) if self.label else '[none]' )) if addr['label'] == self.label: ymsg('\nLabel is unchanged, operation cancelled')