From d326c96af83f5e5102009e6b94817be173e27aa6 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 11 Oct 2023 12:58:50 +0000 Subject: [PATCH] pylint throughout (excluding tests) - various cleanups --- mmgen/addrdata.py | 2 +- mmgen/addrfile.py | 2 +- mmgen/addrlist.py | 8 ++++---- mmgen/altcoin.py | 2 +- mmgen/amt.py | 6 +++--- mmgen/autosign.py | 14 +++++++------- mmgen/baseconv.py | 2 +- mmgen/bip39.py | 20 ++++++++++---------- mmgen/cfg.py | 17 ++++++----------- mmgen/cfgfile.py | 2 +- mmgen/contrib/ed25519.py | 2 +- mmgen/daemon.py | 2 +- mmgen/msg.py | 4 ++-- mmgen/obj.py | 2 +- mmgen/proto/btc/regtest.py | 4 ++-- mmgen/proto/btc/tw/txhistory.py | 4 +++- mmgen/proto/eth/tx/new.py | 4 ++-- mmgen/proto/xmr/rpc.py | 8 ++++---- mmgen/sha2.py | 2 +- mmgen/term.py | 2 +- mmgen/tw/json.py | 2 +- mmgen/tw/prune.py | 4 ++-- mmgen/tx/__init__.py | 2 +- mmgen/tx/base.py | 2 +- mmgen/tx/completed.py | 2 +- mmgen/tx/new.py | 4 ++-- mmgen/ui.py | 4 ++-- mmgen/util2.py | 12 +++++++++--- mmgen/wallet/base.py | 2 +- mmgen/wallet/incog_hidden.py | 2 +- mmgen/xmrseed.py | 7 +++++-- mmgen/xmrwallet.py | 4 +--- 32 files changed, 80 insertions(+), 76 deletions(-) diff --git a/mmgen/addrdata.py b/mmgen/addrdata.py index fd3c6b24..da1f4028 100755 --- a/mmgen/addrdata.py +++ b/mmgen/addrdata.py @@ -58,7 +58,7 @@ class AddrData(MMGenObject): self.al_ids[addrlist.al_id] = addrlist return True else: - raise TypeError(f'Error: object {addrlist!r} is not of type AddrList') + raise TypeError(f'Error: object {addrlist!r} is not an instance of AddrList') def make_reverse_dict(self,coinaddrs): d = MMGenDict() diff --git a/mmgen/addrfile.py b/mmgen/addrfile.py index ff969b41..dffc3ad1 100755 --- a/mmgen/addrfile.py +++ b/mmgen/addrfile.py @@ -182,7 +182,7 @@ class AddrFile(MMGenObject): f'Key doesn’t match address!\n {e.sec.wif}\n {e.addr}') p.cfg._util.qmsg(' - done') - if self.cfg.yes or p.ka_validity_chk == True: + if self.cfg.yes or p.ka_validity_chk: verify_keys() else: from .ui import keypress_confirm diff --git a/mmgen/addrlist.py b/mmgen/addrlist.py index 0cb446d3..30a4a8f7 100755 --- a/mmgen/addrlist.py +++ b/mmgen/addrlist.py @@ -107,15 +107,15 @@ class AddrListIDStr(str,Hilite): def __new__(cls,addrlist,fmt_str=None): idxs = [e.idx for e in addrlist.data] prev = idxs[0] - ret = prev, + ret = [prev] for i in idxs[1:]: if i == prev + 1: if i == idxs[-1]: - ret += '-', i + ret.extend(['-', i]) else: if prev != ret[-1]: - ret += '-', prev - ret += ',', i + ret.extend(['-', prev]) + ret.extend([',', i]) prev = i s = ''.join(map(str,ret)) diff --git a/mmgen/altcoin.py b/mmgen/altcoin.py index e6bad08f..c4f48359 100755 --- a/mmgen/altcoin.py +++ b/mmgen/altcoin.py @@ -45,7 +45,7 @@ def test_equal(desc,a,b,*cdata): if type(a) is int: a = hex(a) b = hex(b) - (network,coin,e,b_desc,verbose) = cdata + (network,coin,_,b_desc,verbose) = cdata if verbose: msg(f' {desc:20}: {a!r}') if a != b: diff --git a/mmgen/amt.py b/mmgen/amt.py index f1850abf..51ded7ac 100755 --- a/mmgen/amt.py +++ b/mmgen/amt.py @@ -71,7 +71,7 @@ class CoinAmt(Decimal,Hilite,InitErrors): # abstract class return int(ret) @classmethod - def fmtc(cls): + def fmtc(cls,*args,**kwargs): cls.method_not_implemented() def fmt( @@ -80,7 +80,7 @@ class CoinAmt(Decimal,Hilite,InitErrors): # abstract class iwidth = 1, # width of the integer part prec = None ): - s = self.__str__() + s = str(self) prec = prec or self.max_prec if '.' in s: @@ -94,7 +94,7 @@ class CoinAmt(Decimal,Hilite,InitErrors): # abstract class color = color ) def hl(self,color=True): - return self.colorize(self.__str__(),color=color) + return self.colorize(str(self),color=color) # fancy highlighting with coin unit, enclosure, formatting def hl2(self,color=True,unit=False,fs='{}',encl=''): diff --git a/mmgen/autosign.py b/mmgen/autosign.py index 211d12c0..fcdbfc5f 100755 --- a/mmgen/autosign.py +++ b/mmgen/autosign.py @@ -87,15 +87,15 @@ class Signable: else: return False - def print_summary(self,txs): + def print_summary(self,signables): if self.cfg.full_summary: bmsg('\nAutosign summary:\n') - msg_r('\n'.join(tx.info.format(terse=True) for tx in txs)) + msg_r('\n'.join(tx.info.format(terse=True) for tx in signables)) return def gen(): - for tx in txs: + for tx in signables: non_mmgen = [o for o in tx.outputs if not o.mmid] if non_mmgen: yield (tx,non_mmgen) @@ -198,10 +198,10 @@ class Signable: die('MsgFileFailedSID',f'Failed Seed IDs: {fmt_list(m.data["failed_sids"],fmt="bare")}') return m - def print_summary(self,messages): + def print_summary(self,signables): gmsg('\nSigned message files:') - for m in messages: - gmsg(' ' + m.signed_filename) + for message in signables: + gmsg(' ' + message.signed_filename) def gen_bad_list(self,bad_files): for f in bad_files: @@ -370,7 +370,7 @@ class Autosign: if e.code != 0: fails += 1 - return False if fails else True + return not fails async def sign_all(self,target_name): target = getattr(Signable,target_name)(self) diff --git a/mmgen/baseconv.py b/mmgen/baseconv.py index 3bf569d0..a36fc87d 100755 --- a/mmgen/baseconv.py +++ b/mmgen/baseconv.py @@ -160,7 +160,7 @@ class baseconv: ( 'seed data' if pad == 'seed' else f'{words_arg!r}:' ) + f' not in {desc} format' ) - ret = sum([wl.index(words[::-1][i])*(base**i) for i in range(len(words))]) + ret = sum(wl.index(words[::-1][i])*(base**i) for i in range(len(words))) bl = ret.bit_length() return ret.to_bytes(max(pad_val,bl//8+bool(bl%8)),'big') diff --git a/mmgen/bip39.py b/mmgen/bip39.py index ca64fc54..e21ba74b 100755 --- a/mmgen/bip39.py +++ b/mmgen/bip39.py @@ -65,8 +65,8 @@ class bip39(baseconv): seed_bits = seed_len * 8 if in_bytes else seed_len * 4 if in_hex else seed_len try: return cls.constants[seed_bits].mn_len - except: - raise ValueError(f'{seed_bits!r}: invalid seed length for BIP39 mnemonic') + except Exception as e: + raise ValueError(f'{seed_bits!r}: invalid seed length for BIP39 mnemonic') from e def tobytes(self,*args,**kwargs): raise NotImplementedError('Method not supported') @@ -74,24 +74,24 @@ class bip39(baseconv): def frombytes(self,*args,**kwargs): raise NotImplementedError('Method not supported') - def tohex(self,words,pad=None): - assert isinstance(words,(list,tuple)),'words must be list or tuple' + def tohex(self,words_arg,pad=None): + assert isinstance(words_arg,(list,tuple)),'words_arg must be list or tuple' assert pad in (None,'seed'), f"{pad}: invalid 'pad' argument (must be None or 'seed')" wl = self.digits - for n,w in enumerate(words): + for n,w in enumerate(words_arg): if w not in wl: die( 'MnemonicError', f'word #{n+1} is not in the BIP39 word list' ) res = ''.join(f'{wl.index(w):011b}' for w in words_arg) for k,v in self.constants.items(): - if len(words) == v.mn_len: + if len(words_arg) == v.mn_len: bitlen = k break else: - die( 'MnemonicError', f'{len(words)}: invalid BIP39 seed phrase length' ) + die( 'MnemonicError', f'{len(words_arg)}: invalid BIP39 seed phrase length' ) seed_bin = res[:bitlen] chk_bin = res[bitlen:] @@ -108,13 +108,13 @@ class bip39(baseconv): return seed_hex - def fromhex(self,seed_hex,pad=None,tostr=False): - assert is_hex_str(seed_hex),'seed data not a hexadecimal string' + def fromhex(self,hexstr,pad=None,tostr=False): + assert is_hex_str(hexstr),'seed data not a hexadecimal string' assert tostr is False,"'tostr' must be False for 'bip39'" assert pad in (None,'seed'), f"{pad}: invalid 'pad' argument (must be None or 'seed')" wl = self.digits - seed_bytes = bytes.fromhex(seed_hex) + seed_bytes = bytes.fromhex(hexstr) bitlen = len(seed_bytes) * 8 assert bitlen in self.constants, f'{bitlen}: invalid seed bit length' diff --git a/mmgen/cfg.py b/mmgen/cfg.py index 0a4dfeaf..42cbb8da 100755 --- a/mmgen/cfg.py +++ b/mmgen/cfg.py @@ -368,31 +368,27 @@ class Config(Lockable): """ location of mmgen.cfg """ - if hasattr(self,'_data_dir_root'): - return self._data_dir_root - else: + if not hasattr(self,'_data_dir_root'): if self._data_dir_root_override: self._data_dir_root = os.path.normpath(os.path.abspath(self._data_dir_root_override)) elif self.test_suite: self._data_dir_root = self.test_datadir else: self._data_dir_root = os.path.join(gc.home_dir,'.'+gc.proj_name.lower()) - return self._data_dir_root + return self._data_dir_root @property def data_dir(self): """ location of wallet and other data - same as data_dir_root for mainnet """ - if hasattr(self,'_data_dir'): - return self._data_dir - else: + if not hasattr(self,'_data_dir'): self._data_dir = os.path.normpath(os.path.join(*{ 'regtest': (self.data_dir_root, 'regtest', self.coin.lower(), (self.regtest_user or 'none') ), 'testnet': (self.data_dir_root, 'testnet'), 'mainnet': (self.data_dir_root,), }[self.network] )) - return self._data_dir + return self._data_dir def __init__( self, @@ -855,14 +851,13 @@ def fmt_opt(o): return '--' + o.replace('_','-') def opt_postproc_debug(cfg): - a = [k for k in dir(cfg) if k[:2] != '__' and getattr(cfg,k) != None] - b = [k for k in dir(cfg) if k[:2] != '__' and getattr(cfg,k) == None] + none_opts = [k for k in dir(cfg) if k[:2] != '__' and getattr(cfg,k) is None] from .util import Msg Msg('\n Configuration opts:') for e in [d for d in dir(cfg) if d[:2] != '__']: Msg(f' {e:<20}: {getattr(cfg,e)}') Msg(" Configuration opts set to 'None':") - Msg(' {}\n'.format('\n '.join(b))) + Msg(' {}\n'.format('\n '.join(none_opts))) Msg('\n=== end opts.py debug ===\n') def conv_type( diff --git a/mmgen/cfgfile.py b/mmgen/cfgfile.py index 30937375..98390148 100755 --- a/mmgen/cfgfile.py +++ b/mmgen/cfgfile.py @@ -90,7 +90,7 @@ class cfg_file: return gen_lines() @classmethod - def get_cls_by_id(self,id_str): + def get_cls_by_id(cls,id_str): d = { 'usr': CfgFileUsr, 'sys': CfgFileSampleSys, diff --git a/mmgen/contrib/ed25519.py b/mmgen/contrib/ed25519.py index cddb0f95..ea273013 100755 --- a/mmgen/contrib/ed25519.py +++ b/mmgen/contrib/ed25519.py @@ -55,4 +55,4 @@ def encodepoint(P): x = P[0] y = P[1] bits = [(y >> i) & 1 for i in range(b-1)] + [x & 1] - return bytes([sum([bits[i * 8 + j] << j for j in range(8)]) for i in range(b//8)]) + return bytes([sum(bits[i * 8 + j] << j for j in range(8)) for i in range(b//8)]) diff --git a/mmgen/daemon.py b/mmgen/daemon.py index 5ac6bddb..900470f3 100755 --- a/mmgen/daemon.py +++ b/mmgen/daemon.py @@ -268,7 +268,7 @@ class RPCDaemon(Daemon): @property def start_cmd(self): - return ([self.exec_fn] + self.daemon_args + self.usr_daemon_args) + return [self.exec_fn] + self.daemon_args + self.usr_daemon_args class CoinDaemon(Daemon): networks = ('mainnet','testnet','regtest') diff --git a/mmgen/msg.py b/mmgen/msg.py index 45b9d639..b0caac30 100755 --- a/mmgen/msg.py +++ b/mmgen/msg.py @@ -256,7 +256,7 @@ class coin_msg: from .wallet import Wallet wallet_seeds = [Wallet(cfg=self.cfg,fn=fn).seed for fn in wallet_files] need_sids = remove_dups([al.sid for al in self.addrlists], quiet=True) - saved_seeds = list() + saved_seeds = [] # First try wallet seeds: for sid in need_sids: @@ -363,7 +363,7 @@ class coin_msg: self.data['signatures'] )} -def _get_obj(clsname,cfg,coin=None,network='mainnet',infile=None,data=None,*args,**kwargs): +def _get_obj(clsname,cfg,*args,coin=None,network='mainnet',infile=None,data=None,**kwargs): assert not args, 'msg:_get_obj(): only keyword args allowed' diff --git a/mmgen/obj.py b/mmgen/obj.py index d91c2f8a..41fa4fca 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -32,7 +32,7 @@ def get_obj(objname,*args,**kwargs): - If return_bool is True, return True instead of the object. Only keyword args are accepted. """ - assert args == (), 'get_obj_chk1' + assert not args, 'get_obj_chk1' silent,return_bool = (False,False) if 'silent' in kwargs: diff --git a/mmgen/proto/btc/regtest.py b/mmgen/proto/btc/regtest.py index 35641934..861b26e3 100755 --- a/mmgen/proto/btc/regtest.py +++ b/mmgen/proto/btc/regtest.py @@ -208,7 +208,7 @@ class MMGenRegtest(MMGenObject): async def send(self,addr,amt): gmsg(f'Sending {amt} miner {self.d.coin} to address {addr}') - cp = await self.rpc_call('sendtoaddress',addr,str(amt),wallet='miner') + await self.rpc_call('sendtoaddress',addr,str(amt),wallet='miner') await self.generate(1) async def mempool(self): @@ -256,7 +256,7 @@ class MMGenRegtest(MMGenObject): create_data_dir( self.cfg, self.d.datadir ) os.rmdir(self.d.datadir) - shutil.copytree(source_data_dir,self.d.datadir,symlinks=True) + shutil.copytree(source_rt.d.datadir,self.d.datadir,symlinks=True) await self.start_daemon(reindex=True) await self.rpc_call('stop') diff --git a/mmgen/proto/btc/tw/txhistory.py b/mmgen/proto/btc/tw/txhistory.py index 5b681511..dfb7d795 100755 --- a/mmgen/proto/btc/tw/txhistory.py +++ b/mmgen/proto/btc/tw/txhistory.py @@ -36,6 +36,7 @@ class BitcoinTwTransaction: self.parent = parent self.proto = proto self.rpc = rpc + self.idx = idx self.unspent_info = unspent_info self.tx = tx @@ -296,7 +297,8 @@ Filters/Actions: show [u]nconfirmed, [q]uit menu, r[e]draw: def do_json_dump(*data): nw = f'{self.proto.coin.lower()}-{self.proto.network}' for d,fn_stem in data: - open(f'/tmp/{fn_stem}-{nw}.json','w').write(json.dumps(d,cls=json_encoder)) + with open(f'/tmp/{fn_stem}-{nw}.json','w') as fh: + fh.write(json.dumps(d,cls=json_encoder)) _mmp = namedtuple('mmap_datum',['twmmid','comment']) diff --git a/mmgen/proto/eth/tx/new.py b/mmgen/proto/eth/tx/new.py index 28e8444f..7552f9f1 100755 --- a/mmgen/proto/eth/tx/new.py +++ b/mmgen/proto/eth/tx/new.py @@ -41,7 +41,7 @@ class New(Base,TxBase.New): if self.cfg.contract_data: m = "'--contract-data' option may not be used with token transaction" - assert not 'Token' in self.name, m + assert 'Token' not in self.name, m with open(self.cfg.contract_data) as fp: self.usr_contract_data = HexStr(fp.read().strip()) self.disable_fee_check = True @@ -81,7 +81,7 @@ class New(Base,TxBase.New): async def process_cmd_args(self,cmd_args,ad_f,ad_w): lc = len(cmd_args) - if lc == 0 and self.usr_contract_data and not 'Token' in self.name: + if lc == 0 and self.usr_contract_data and 'Token' not in self.name: return if lc != 1: die(1,f'{lc} output{suf(lc)} specified, but Ethereum transactions must have exactly one') diff --git a/mmgen/proto/xmr/rpc.py b/mmgen/proto/xmr/rpc.py index 59f03abe..060b63cd 100755 --- a/mmgen/proto/xmr/rpc.py +++ b/mmgen/proto/xmr/rpc.py @@ -75,7 +75,7 @@ class MoneroRPCClient(RPCClient): self.daemon_version = None def call(self,method,*params,**kwargs): - assert params == (), f'{self.name}.call() accepts keyword arguments only' + assert not params, f'{self.name}.call() accepts keyword arguments only' return self.process_http_resp(self.backend.run_noasync( payload = {'id': 0, 'jsonrpc': '2.0', 'method': method, 'params': kwargs }, timeout = 3600, # allow enough time to sync ≈1,000,000 blocks @@ -83,7 +83,7 @@ class MoneroRPCClient(RPCClient): )) def call_raw(self,method,*params,**kwargs): - assert params == (), f'{self.name}.call() accepts keyword arguments only' + assert not params, f'{self.name}.call() accepts keyword arguments only' return self.process_http_resp(self.backend.run_noasync( payload = kwargs, timeout = self.timeout, @@ -125,7 +125,7 @@ class MoneroWalletRPCClient(MoneroRPCClient): 'refresh', # start_height ) - def call_raw(*args,**kwargs): + def call_raw(self,*args,**kwargs): raise NotImplementedError('call_raw() not implemented for class MoneroWalletRPCClient') async def do_stop_daemon(self,silent=False): @@ -139,7 +139,7 @@ class MoneroWalletRPCClient(MoneroRPCClient): from ...util import msg,msg_r,ymsg from ...color import yellow msg(f'{type(e).__name__}: {e}') - msg_r(yellow(f'Unable to shut down wallet daemon gracefully, so killing process instead...')) + msg_r(yellow('Unable to shut down wallet daemon gracefully, so killing process instead...')) ret = self.daemon.stop(silent=True) ymsg('done') return ret diff --git a/mmgen/sha2.py b/mmgen/sha2.py index 959d78d2..ddb263df 100755 --- a/mmgen/sha2.py +++ b/mmgen/sha2.py @@ -103,7 +103,7 @@ class Sha2: def bytesToWords(self): ws = self.wordSize assert len(self.M) % ws == 0 - self.M = tuple([unpack(self.word_fmt,self.M[i*ws:ws+(i*ws)])[0] for i in range(len(self.M) // ws)]) + self.M = tuple(unpack(self.word_fmt,self.M[i*ws:ws+(i*ws)])[0] for i in range(len(self.M) // ws)) def digest(self): return b''.join((pack(self.word_fmt,w) for w in self.H)) diff --git a/mmgen/term.py b/mmgen/term.py index cb082e88..f1da7197 100755 --- a/mmgen/term.py +++ b/mmgen/term.py @@ -31,7 +31,7 @@ try: import tty,termios from select import select _platform = 'linux' -except: +except ImportError: try: import msvcrt _platform = 'mswin' diff --git a/mmgen/tw/json.py b/mmgen/tw/json.py index 08bee2fb..1cd2ddb6 100755 --- a/mmgen/tw/json.py +++ b/mmgen/tw/json.py @@ -123,7 +123,7 @@ class TwJSON: desc2 = 'saved checksum' ) if not await self.check_and_create_wallet(): - return True + return from ..fileutil import get_data_from_file self.data = json.loads(get_data_from_file( self.cfg, filename, quiet=True )) diff --git a/mmgen/tw/prune.py b/mmgen/tw/prune.py index 1c5208d6..301a46d0 100755 --- a/mmgen/tw/prune.py +++ b/mmgen/tw/prune.py @@ -131,8 +131,8 @@ class TwAddressesPrune(TwAddresses): dfl[desc] = auto[desc] and prune skip_all_used = auto['used'] and not dfl['used'] if auto[desc]: # we’ve switched to auto mode, so go back and fix up all previous entries - for addrnum in addrnums[:n]: - e = parent.disp_data[addrnum-1] + for idx in addrnums[:n]: + e = parent.disp_data[idx-1] if skip_all_used and e.recvd: e.tag = False elif desc == 'amt' and e.amt: diff --git a/mmgen/tx/__init__.py b/mmgen/tx/__init__.py index 489d36ed..a8bafebb 100755 --- a/mmgen/tx/__init__.py +++ b/mmgen/tx/__init__.py @@ -48,7 +48,7 @@ def _get_cls_info(clsname,modname,args,kwargs): if not cls: die(1,f'{ext!r}: unrecognized file extension for CompletedTX') clsname = cls.__name__ - modname = cls.__module__.split('.')[-1] + modname = cls.__module__.rsplit('.',maxsplit=1)[-1] kwargs['proto'] = proto diff --git a/mmgen/tx/base.py b/mmgen/tx/base.py index 186c123a..b8d2d925 100755 --- a/mmgen/tx/base.py +++ b/mmgen/tx/base.py @@ -67,7 +67,7 @@ class MMGenTxIOList(list,MMGenObject): if data: assert isinstance(data,list), 'MMGenTxIOList_check1' else: - data = list() + data = [] list.__init__(self,data) class Base(MMGenObject): diff --git a/mmgen/tx/completed.py b/mmgen/tx/completed.py index 83958c5b..82a30d4f 100755 --- a/mmgen/tx/completed.py +++ b/mmgen/tx/completed.py @@ -20,7 +20,7 @@ class Completed(Base): """ filename_api = True - def __init__(self,cfg,filename=None,data=None,quiet_open=False,*args,**kwargs): + def __init__(self,cfg,*args,filename=None,data=None,quiet_open=False,**kwargs): assert (filename or data) and not (filename and data), 'CompletedTX_chk1' diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index 4a9a141e..9a914a0a 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -325,8 +325,8 @@ class New(Base): die(1,f'{addr!r}: not an MMGen ID or {self.coin} address') found = False - for idx in range(len(unspent)): - if getattr(unspent[idx],attr) == addr: + for idx,us in enumerate(unspent): + if getattr(us,attr) == addr: yield idx2num(idx) found = True diff --git a/mmgen/ui.py b/mmgen/ui.py index 5be28496..03ca61b3 100755 --- a/mmgen/ui.py +++ b/mmgen/ui.py @@ -102,10 +102,10 @@ def keypress_confirm( reply = get_char(prompt,immed_chars='yYnN').strip('\n\r') if not reply: msg_r(nl) - return True if default_yes else False + return default_yes elif reply in 'yYnN': msg_r(nl) - return True if reply in 'yY' else False + return reply in 'yY' else: msg_r('\nInvalid reply\n' if verbose else '\r') diff --git a/mmgen/util2.py b/mmgen/util2.py index 8d70392b..6fe474b8 100755 --- a/mmgen/util2.py +++ b/mmgen/util2.py @@ -82,11 +82,17 @@ def int2bytespec(n,spec,fmt,print_sym=True,strip=False,add_space=False): else: die(1,f'{spec!r}: unrecognized bytespec') + ret = f'{n/spec2int(spec):{fmt}f}' if strip: - ret = '{:{}f}'.format(n/spec2int(spec),fmt).rstrip('0') - return ret + ('0' if ret.endswith('.') else '') + ((' ' if add_space else '') + spec if print_sym else '') + ret = ret.rstrip('0') + return ( + ret + + ('0' if ret.endswith('.') else '') + + ((' ' if add_space else '') + spec if print_sym else '') ) else: - return '{:{}f}'.format(n/spec2int(spec),fmt) + ((' ' if add_space else '') + spec if print_sym else '') + return ( + ret + + ((' ' if add_space else '') + spec if print_sym else '') ) def parse_bytespec(nbytes): m = re.match(r'([0123456789.]+)(.*)',nbytes) diff --git a/mmgen/wallet/base.py b/mmgen/wallet/base.py index 6a5b46cf..0b0f456f 100755 --- a/mmgen/wallet/base.py +++ b/mmgen/wallet/base.py @@ -21,7 +21,7 @@ from . import wallet_data,get_wallet_cls class WalletMeta(type): def __init__(cls,name,bases,namespace): - t = cls.__module__.split('.')[-1] + t = cls.__module__.rsplit('.',maxsplit=1)[-1] if t in wallet_data: for k,v in wallet_data[t]._asdict().items(): setattr(cls,k,v) diff --git a/mmgen/wallet/incog_hidden.py b/mmgen/wallet/incog_hidden.py index 4993a086..fbb23956 100755 --- a/mmgen/wallet/incog_hidden.py +++ b/mmgen/wallet/incog_hidden.py @@ -81,7 +81,7 @@ class wallet(wallet): self.cfg._util.qmsg(f'Data read from file {self.infile.name!r} at offset {d.hincog_offset}') # overrides method in Wallet - def write_to_file(self): + def write_to_file(self,**kwargs): d = self.ssdata self._format() self.cfg._util.compare_or_die( diff --git a/mmgen/xmrseed.py b/mmgen/xmrseed.py index b74e1063..a6297426 100755 --- a/mmgen/xmrseed.py +++ b/mmgen/xmrseed.py @@ -46,10 +46,13 @@ class xmrseed(baseconv): wstr = ''.join(word[:3] for word in words) return words[crc32(wstr.encode()) % len(words)] - def tobytes(self,words,pad=None): - assert isinstance(words,(list,tuple)),'words must be list or tuple' + def tobytes(self,words_arg,pad=None): + + assert isinstance(words_arg,(list,tuple)),'words must be list or tuple' assert pad is None, f"{pad}: invalid 'pad' argument (must be None)" + words = words_arg + desc = self.desc.short wl = self.digits base = len(wl) diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index b28de6cb..bf6d78f5 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -1010,7 +1010,7 @@ class MoneroWalletOps: msg('\n Addresses of account #{} ({}):'.format( account, accts_data['subaddress_accounts'][account]['label'])) - fs = ' {:6} {:18} {:%s} {}' % max( [len(e['label']) for e in d], default=0 ) + fs = ' {:6} {:18} {:%s} {}' % max((len(e['label']) for e in d), default=0) msg(fs.format('Index ','Address','Label','Used')) for e in d: msg(fs.format( @@ -1881,8 +1881,6 @@ class MoneroWalletOps: super().__init__(cfg,uarg_tuple) - check_uopts = MoneroWalletOps.submit.check_uopts - self.tx = MoneroMMGenTX.Signed( self.cfg, Path(uarg.infile) ) if self.cfg.tx_relay_daemon: