From b660ba4235546968b6855857cc1966c28ed4d738 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 11 Oct 2023 12:58:49 +0000 Subject: [PATCH] pylint throughout (excluding tests) - use "is" for bool,None,type equality --- mmgen/addrfile.py | 10 +++++----- mmgen/addrgen.py | 4 ++-- mmgen/addrlist.py | 8 ++++---- mmgen/altcoin.py | 6 +++--- mmgen/amt.py | 2 +- mmgen/baseconv.py | 6 +++--- mmgen/bip39.py | 2 +- mmgen/cfg.py | 4 ++-- mmgen/cfgfile.py | 2 +- mmgen/crypto.py | 2 +- mmgen/fileutil.py | 2 +- mmgen/key.py | 4 ++-- mmgen/obj.py | 14 +++++++------- mmgen/proto/btc/regtest.py | 2 +- mmgen/proto/btc/rpc.py | 4 ++-- mmgen/proto/btc/tw/ctl.py | 2 +- mmgen/proto/btc/tw/txhistory.py | 2 +- mmgen/proto/btc/tx/bump.py | 2 +- mmgen/proto/btc/tx/info.py | 2 +- mmgen/proto/btc/tx/new.py | 4 ++-- mmgen/proto/btc/tx/online.py | 2 +- mmgen/proto/eth/contract.py | 2 +- mmgen/proto/eth/rpc.py | 2 +- mmgen/proto/eth/tw/ctl.py | 4 ++-- mmgen/proto/eth/tx/new.py | 2 +- mmgen/protocol.py | 10 +++++----- mmgen/rpc.py | 6 +++--- mmgen/seedsplit.py | 2 +- mmgen/sha2.py | 2 +- mmgen/subseed.py | 6 +++--- mmgen/tw/addresses.py | 4 ++-- mmgen/tw/ctl.py | 6 +++--- mmgen/tw/view.py | 2 +- mmgen/tx/base.py | 2 +- mmgen/tx/bump.py | 6 +++--- mmgen/tx/file.py | 4 ++-- mmgen/tx/sign.py | 2 +- mmgen/util.py | 4 ++-- mmgen/util2.py | 2 +- mmgen/wallet/mmgen.py | 2 +- mmgen/wallet/seed.py | 2 +- mmgen/xmrseed.py | 4 ++-- mmgen/xmrwallet.py | 12 ++++++------ 43 files changed, 87 insertions(+), 87 deletions(-) diff --git a/mmgen/addrfile.py b/mmgen/addrfile.py index 8bb7b91c..5d27c668 100755 --- a/mmgen/addrfile.py +++ b/mmgen/addrfile.py @@ -110,7 +110,7 @@ class AddrFile(MMGenObject): fs = ' {:<%s} {:<34}{}' % len(str(p.data[-1].idx)) for e in p.data: c = ' ' + e.comment if add_comments and e.comment else '' - if type(p) == KeyList: + if type(p) is KeyList: out.append(fs.format( e.idx, f'{p.al_id.mmtype.wif_label}: {e.sec.wif}', c )) elif type(p).__name__ == 'PasswordList': out.append(fs.format(e.idx,e.passwd,c)) @@ -119,7 +119,7 @@ class AddrFile(MMGenObject): if p.has_keys: if self.cfg.b16: out.append(fs.format( '', f'orig_hex: {e.sec.orig_bytes.hex()}', c )) - if type(self) != ViewKeyAddrFile: + if type(self) is not ViewKeyAddrFile: out.append(fs.format( '', f'{p.al_id.mmtype.wif_label}: {e.sec.wif}', c )) for k in ('viewkey','wallet_passwd'): v = getattr(e,k) @@ -154,7 +154,7 @@ class AddrFile(MMGenObject): a = le(**{ 'proto': p.proto, 'idx':int(idx), p.main_attr:addr, 'comment':comment }) if p.has_keys: # order: wif,(orig_hex),viewkey,wallet_passwd - if type(self) != ViewKeyAddrFile: + if type(self) is not ViewKeyAddrFile: d = self.get_line(lines) assert d[0] == p.al_id.mmtype.wif_label+':', iifs.format(d[0],p.al_id.mmtype.wif_label) a.sec = PrivKey(proto=p.proto,wif=d[1]) @@ -168,7 +168,7 @@ class AddrFile(MMGenObject): ret.append(a) - if type(self) != ViewKeyAddrFile and p.has_keys and p.ka_validity_chk != False: + if type(self) is not ViewKeyAddrFile and p.has_keys and p.ka_validity_chk is not False: def verify_keys(): from .addrgen import KeyGenerator,AddrGenerator @@ -230,7 +230,7 @@ class AddrFile(MMGenObject): proto = init_proto( p.cfg, coin=coin, network=network ) - if mmtype_key == None: + if mmtype_key is None: mmtype_key = proto.mmtypes[0] return ( proto, proto.addr_type(mmtype_key) ) diff --git a/mmgen/addrgen.py b/mmgen/addrgen.py index 5a212bf2..c0578536 100755 --- a/mmgen/addrgen.py +++ b/mmgen/addrgen.py @@ -66,9 +66,9 @@ def AddrGenerator(cfg,proto,addr_type): from .addr import MMGenAddrType - if type(addr_type) == str: + if type(addr_type) is str: addr_type = MMGenAddrType(proto=proto,id_str=addr_type) - elif type(addr_type) == MMGenAddrType: + elif type(addr_type) is MMGenAddrType: assert addr_type in proto.mmtypes, f'{addr_type}: invalid address type for coin {proto.coin}' else: raise TypeError(f'{type(addr_type)}: incorrect argument type for {cls.__name__}()') diff --git a/mmgen/addrlist.py b/mmgen/addrlist.py index f4cdc216..0cb446d3 100755 --- a/mmgen/addrlist.py +++ b/mmgen/addrlist.py @@ -216,16 +216,16 @@ class AddrList(MMGenObject): # Address info for a single seed ID self.fmt_data = '' self.chksum = None - if self.al_id == None: + if self.al_id is None: return - if type(self) == ViewKeyAddrList: + if type(self) is ViewKeyAddrList: if not 'viewkey' in self.al_id.mmtype.extra_attrs: die(1,f'viewkeys not supported for address type {self.al_id.mmtype.desc!r}') self.id_str = AddrListIDStr(self) - if type(self) == KeyList: + if type(self) is KeyList: return if do_chksum and not skip_chksum: @@ -288,7 +288,7 @@ class AddrList(MMGenObject): # Address info for a single seed ID e.viewkey = ag.to_viewkey(data) if gen_wallet_passwd: e.wallet_passwd = self.gen_wallet_passwd( - e.viewkey.encode() if type(self) == ViewKeyAddrList else e.sec ) + e.viewkey.encode() if type(self) is ViewKeyAddrList else e.sec ) elif self.gen_passwds: e.passwd = self.gen_passwd(e.sec) # TODO - own type diff --git a/mmgen/altcoin.py b/mmgen/altcoin.py index 3664d3eb..bbf309e9 100755 --- a/mmgen/altcoin.py +++ b/mmgen/altcoin.py @@ -42,7 +42,7 @@ from .cfg import gc,Config from .util import msg def test_equal(desc,a,b,*cdata): - if type(a) == int: + if type(a) is int: a = hex(a) b = hex(b) (network,coin,e,b_desc,verbose) = cdata @@ -625,7 +625,7 @@ class CoinInfo(object): except: pass else: - if bl == True or coin in bl: + if bl is True or coin in bl: if verbose: msg(f'Tool {tool!r} blacklisted for coin {coin}, addr_type {addr_type!r}') return None @@ -708,7 +708,7 @@ def init_genonly_altcoins(usr_coin=None,testnet=False): networks = ['mainnet'] + (['testnet'] if testnet else []) network = 'testnet' if testnet else 'mainnet' - if usr_coin == None: + if usr_coin is None: for network in networks: data[network] = CoinInfo.get_supported_coins(network) trust_level = 0 diff --git a/mmgen/amt.py b/mmgen/amt.py index aef7ca8c..f1850abf 100755 --- a/mmgen/amt.py +++ b/mmgen/amt.py @@ -47,7 +47,7 @@ class CoinAmt(Decimal,Hilite,InitErrors): # abstract class try: if from_unit: assert from_unit in cls.units, f'{from_unit!r}: unrecognized denomination for {cls.__name__}' - assert type(num) == int,'value is not an integer' + assert type(num) is int,'value is not an integer' me = Decimal.__new__(cls,num * getattr(cls,from_unit)) elif from_decimal: assert isinstance(num,Decimal), f'number must be of type Decimal, not {type(num).__name__})' diff --git a/mmgen/baseconv.py b/mmgen/baseconv.py index a9e53db5..e87e6a35 100755 --- a/mmgen/baseconv.py +++ b/mmgen/baseconv.py @@ -121,9 +121,9 @@ class baseconv(object): If 'seed', output length will be mapped from input length using data in seedlen_map. If an integer, the string, hex string or byte output will be padded to this length. """ - if pad == None: + if pad is None: return 0 - elif type(pad) == int: + elif type(pad) is int: return pad elif pad == 'seed': return seed_pad_func() @@ -132,7 +132,7 @@ class baseconv(object): def tohex(self,words_arg,pad=None): "convert string or list data of instance base to a hexadecimal string" - return self.tobytes(words_arg,pad//2 if type(pad)==int else pad).hex() + return self.tobytes(words_arg, pad//2 if type(pad) is int else pad).hex() def tobytes(self,words_arg,pad=None): "convert string or list data of instance base to byte string" diff --git a/mmgen/bip39.py b/mmgen/bip39.py index fcc5495e..ca64fc54 100755 --- a/mmgen/bip39.py +++ b/mmgen/bip39.py @@ -110,7 +110,7 @@ class bip39(baseconv): def fromhex(self,seed_hex,pad=None,tostr=False): assert is_hex_str(seed_hex),'seed data not a hexadecimal string' - assert tostr == False,"'tostr' must be False for 'bip39'" + 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 diff --git a/mmgen/cfg.py b/mmgen/cfg.py index a2237d63..0a4dfeaf 100755 --- a/mmgen/cfg.py +++ b/mmgen/cfg.py @@ -675,7 +675,7 @@ class Config(Lockable): def _die_on_incompatible_opts(self): for group in self._incompatible_opts: - bad = [k for k in self.__dict__ if k in group and getattr(self,k) != None] + bad = [k for k in self.__dict__ if k in group and getattr(self,k) is not None] if len(bad) > 1: die(1,'Conflicting options: {}'.format(', '.join(map(fmt_opt,bad)))) @@ -881,7 +881,7 @@ def conv_type( d = f' in {src!r}' if src else '', e = type(refval).__name__ )) - if type(refval) == bool: + if type(refval) is bool: v = str(val).lower() ret = ( True if v in ('true','yes','1','on') else diff --git a/mmgen/cfgfile.py b/mmgen/cfgfile.py index 219d5555..30937375 100755 --- a/mmgen/cfgfile.py +++ b/mmgen/cfgfile.py @@ -148,7 +148,7 @@ class cfg_file_sample(cfg_file): if line == '': in_chunk = False elif line.startswith('#'): - if in_chunk == False: + if in_chunk is False: if chunk: yield process_chunk(chunk,last_nonblank) chunk = [line] diff --git a/mmgen/crypto.py b/mmgen/crypto.py index 7ec3cde2..49a2d191 100755 --- a/mmgen/crypto.py +++ b/mmgen/crypto.py @@ -306,7 +306,7 @@ class Crypto: desc, urand = {'data':b'', 'counter':0} ): - assert type(rand_bytes) == bytes, 'add_user_random_chk1' + assert type(rand_bytes) is bytes, 'add_user_random_chk1' if self.cfg.usr_randchars: diff --git a/mmgen/fileutil.py b/mmgen/fileutil.py index 1e1cd443..7e49db28 100755 --- a/mmgen/fileutil.py +++ b/mmgen/fileutil.py @@ -170,7 +170,7 @@ def write_data_to_file( if cfg.quiet: ask_overwrite = False - if ask_write_default_yes == False or ask_write_prompt: + if ask_write_default_yes is False or ask_write_prompt: ask_write = True def do_stdout(): diff --git a/mmgen/key.py b/mmgen/key.py index 3333837e..2fe0753e 100755 --- a/mmgen/key.py +++ b/mmgen/key.py @@ -74,7 +74,7 @@ class PrivKey(bytes,Hilite,InitErrors,MMGenObject): return s if wif: try: - assert s == None,"'wif' and key hex args are mutually exclusive" + assert s is None,"'wif' and key hex args are mutually exclusive" assert wif.isascii() and wif.isalnum(), 'not an ASCII alphanumeric string' k = proto.decode_wif(wif) # raises exception on error me = bytes.__new__(cls,k.sec) @@ -100,7 +100,7 @@ class PrivKey(bytes,Hilite,InitErrors,MMGenObject): me = bytes.__new__(cls,s) else: assert compressed is not None, "'compressed' arg missing" - assert type(compressed) == bool,( + assert type(compressed) is bool,( f"'compressed' must be of type bool, not {type(compressed).__name__}" ) me = bytes.__new__( cls, proto.preprocess_key(s,pubkey_type) ) me.wif = WifKey( proto, proto.encode_wif(me,pubkey_type,compressed) ) diff --git a/mmgen/obj.py b/mmgen/obj.py index 3faa0d88..3329f7f2 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -126,7 +126,7 @@ class ImmutableAttr: # Descriptor else: "check this attribute's type" def assign_with_check(instance,value): - if type(value) == dtype: + if type(value) is dtype: return value raise TypeError('Attribute {!r} of {} instance must of type {}'.format( self.name, @@ -171,7 +171,7 @@ class ListItemAttr(ImmutableAttr): return None def setattr_condition(self,instance): - return getattr(instance,self.name) == None or self.reassign_ok + return getattr(instance,self.name) is None or self.reassign_ok def __delete__(self,instance): if self.delete_ok: @@ -205,7 +205,7 @@ class MMGenListItem(MMGenObject): raise ValueError(f'Non-keyword args not allowed in {type(self).__name__!r} constructor') for k,v in kwargs.items(): - if v != None: + if v is not None: setattr(self,k,v) # Require all immutables to be initialized. Check performed only when testing. @@ -274,11 +274,11 @@ class Int(int,Hilite,InitErrors): return n try: me = int.__new__(cls,str(n),base) - if cls.min_val != None: + if cls.min_val is not None: assert me >= cls.min_val, f'is less than cls.min_val ({cls.min_val})' - if cls.max_val != None: + if cls.max_val is not None: assert me <= cls.max_val, f'is greater than cls.max_val ({cls.max_val})' - if cls.max_digits != None: + if cls.max_digits is not None: assert len(str(me)) <= cls.max_digits, f'has more than {cls.max_digits} digits' return me except Exception as e: @@ -314,7 +314,7 @@ class HexStr(str,Hilite,InitErrors): def __new__(cls,s,case=None): if isinstance(s,cls): return s - if case == None: + if case is None: case = cls.hexcase from .util import hexdigits_lc,hexdigits_uc try: diff --git a/mmgen/proto/btc/regtest.py b/mmgen/proto/btc/regtest.py index 0fc314a8..35641934 100755 --- a/mmgen/proto/btc/regtest.py +++ b/mmgen/proto/btc/regtest.py @@ -229,7 +229,7 @@ class MMGenRegtest(MMGenObject): async def fork(self,coin): # currently disabled proto = init_proto( self.cfg, coin, False ) - if not [f for f in proto.forks if f[2] == proto.coin.lower() and f[3] == True]: + if not [f for f in proto.forks if f[2] == proto.coin.lower() and f[3] is True]: die(1,f'Coin {proto.coin} is not a replayable fork of coin {coin}') gmsg(f'Creating fork from coin {coin} to coin {proto.coin}') diff --git a/mmgen/proto/btc/rpc.py b/mmgen/proto/btc/rpc.py index 7ed0b0ce..fb3cf1ff 100755 --- a/mmgen/proto/btc/rpc.py +++ b/mmgen/proto/btc/rpc.py @@ -170,7 +170,7 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit): if block0 != self.proto.block0: raise ValueError(f'Invalid Genesis block for {self.proto.cls_name} protocol') for fork in self.proto.forks: - if fork.height == None or self.blockcount < fork.height: + if fork.height is None or self.blockcount < fork.height: break if fork.hash != await self.call('getblockhash',fork.height): die(3,f'Bad block hash at fork block {fork.height}. Is this the {fork.name} chain?') @@ -286,7 +286,7 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit): d = self.cached['blockchaininfo'] try: - if d['softforks']['segwit']['active'] == True: + if d['softforks']['segwit']['active'] is True: return True except: pass diff --git a/mmgen/proto/btc/tw/ctl.py b/mmgen/proto/btc/tw/ctl.py index 72b79a54..dd082b6e 100755 --- a/mmgen/proto/btc/tw/ctl.py +++ b/mmgen/proto/btc/tw/ctl.py @@ -52,7 +52,7 @@ class BitcoinTwCtl(TwCtl): async def rescan_blockchain(self,start,stop): start = start or 0 - endless = stop == None + endless = stop is None CR = '\n' if self.cfg.test_suite else '\r' if not ( start >= 0 and (stop if stop is not None else start) >= start ): diff --git a/mmgen/proto/btc/tw/txhistory.py b/mmgen/proto/btc/tw/txhistory.py index bc8cdd50..5b681511 100755 --- a/mmgen/proto/btc/tw/txhistory.py +++ b/mmgen/proto/btc/tw/txhistory.py @@ -141,7 +141,7 @@ class BitcoinTwTransaction: return self.parent.date_formatter[age_fmt](self.rpc,self.time) def txid_disp(self,color,width=None): - return self.txid.hl(color=color) if width == None else self.txid.truncate(width=width,color=color) + return self.txid.hl(color=color) if width is None else self.txid.truncate(width=width,color=color) def vouts_list_disp(self,src,color,indent=''): diff --git a/mmgen/proto/btc/tx/bump.py b/mmgen/proto/btc/tx/bump.py index 93e578c5..545ec133 100755 --- a/mmgen/proto/btc/tx/bump.py +++ b/mmgen/proto/btc/tx/bump.py @@ -32,7 +32,7 @@ class Bump(Completed,New,TxBase.Bump): def convert_and_check_fee(self,fee,desc): ret = super().convert_and_check_fee(fee,desc) - if ret == False: + if ret is False: return ret if ret < self.min_fee: msg('{} {c}: {} fee too small. Minimum fee: {} {c} ({} {})'.format( diff --git a/mmgen/proto/btc/tx/info.py b/mmgen/proto/btc/tx/info.py index 8a7609fb..80758683 100755 --- a/mmgen/proto/btc/tx/info.py +++ b/mmgen/proto/btc/tx/info.py @@ -124,7 +124,7 @@ class TxInfo(TxInfo): # format (the number of seconds elapsed since 1970-01-01T00:00 UTC). The transaction can be # added to any block whose block time is greater than the locktime. num = locktime or self.tx.locktime - if num == None: + if num is None: return '(None)' elif num >= 5 * 10**6: import time diff --git a/mmgen/proto/btc/tx/new.py b/mmgen/proto/btc/tx/new.py index 175ad579..e1bf9320 100755 --- a/mmgen/proto/btc/tx/new.py +++ b/mmgen/proto/btc/tx/new.py @@ -69,10 +69,10 @@ class New(Base,TxBase.New): def convert_and_check_fee(self,fee,desc): abs_fee = self.feespec2abs(fee,self.estimate_size()) - if abs_fee == None: + if abs_fee is None: raise ValueError(f'{fee}: cannot convert {self.rel_fee_desc} to {self.coin}' + ' because transaction size is unknown') - if abs_fee == False: + if abs_fee is False: err = f'{fee!r}: invalid TX fee (not a {self.coin} amount or {self.rel_fee_desc} specification)' elif abs_fee > self.proto.max_tx_fee: err = f'{abs_fee} {self.coin}: {desc} fee too large (maximum fee: {self.proto.max_tx_fee} {self.coin})' diff --git a/mmgen/proto/btc/tx/online.py b/mmgen/proto/btc/tx/online.py index 06cd5600..847ff0c8 100755 --- a/mmgen/proto/btc/tx/online.py +++ b/mmgen/proto/btc/tx/online.py @@ -50,7 +50,7 @@ class OnlineSigned(Signed,TxBase.OnlineSigned): errmsg = str(e) ret = False - if ret == False: # TODO: test send errors + if ret is False: # TODO: test send errors if errmsg.count('Signature must use SIGHASH_FORKID'): m = ('The Aug. 1 2017 UAHF has activated on this chain.\n' + 'Re-run the script with the --coin=bch option.' ) diff --git a/mmgen/proto/eth/contract.py b/mmgen/proto/eth/contract.py index 5bb0b0f2..d32367e8 100755 --- a/mmgen/proto/eth/contract.py +++ b/mmgen/proto/eth/contract.py @@ -131,7 +131,7 @@ class TokenCommon(MMGenObject): if chain_id is None: res = await self.rpc.call('eth_chainId') - chain_id = None if res == None else int(res,16) + chain_id = None if res is None else int(res,16) tx = Transaction(**tx_in).sign(key,chain_id) diff --git a/mmgen/proto/eth/rpc.py b/mmgen/proto/eth/rpc.py index a9cbaddb..a15fd4a4 100755 --- a/mmgen/proto/eth/rpc.py +++ b/mmgen/proto/eth/rpc.py @@ -78,7 +78,7 @@ class EthereumRPCClient(RPCClient,metaclass=AsyncInit): if self.daemon.id in ('parity','openethereum'): if (await self.call('parity_nodeKind'))['capability'] == 'full': self.caps += ('full_node',) - self.chainID = None if ci == None else Int(ci,16) # parity/oe return chainID only for dev chain + self.chainID = None if ci is None else Int(ci,16) # parity/oe return chainID only for dev chain self.chain = (await self.call('parity_chain')).replace(' ','_').replace('_testnet','') elif self.daemon.id in ('geth','erigon'): if self.daemon.network == 'mainnet': diff --git a/mmgen/proto/eth/tw/ctl.py b/mmgen/proto/eth/tw/ctl.py index 6a40499f..d82bd4e8 100755 --- a/mmgen/proto/eth/tw/ctl.py +++ b/mmgen/proto/eth/tw/ctl.py @@ -183,7 +183,7 @@ class EthereumTokenTwCtl(EthereumTwCtl): if not is_coin_addr(proto,token_addr): die( 'InvalidTokenAddress', f'{token_addr!r}: invalid token address' ) else: - assert token_addr == None,'EthereumTokenTwCtl_chk1' + assert token_addr is None,'EthereumTokenTwCtl_chk1' token_addr = await self.sym2addr(proto.tokensym) # returns None on failure if not is_coin_addr(proto,token_addr): die( 'UnrecognizedTokenSymbol', f'Specified token {proto.tokensym!r} could not be resolved!' ) @@ -217,7 +217,7 @@ class EthereumTokenTwCtl(EthereumTwCtl): cache = self.cur_eth_balances r = self.data['accounts'] ret = None if force_rpc else self.get_cached_balance(addr,cache,r) - if ret == None: + if ret is None: ret = await super().rpc_get_balance(addr) self.cache_balance(addr,ret,cache,r) return ret diff --git a/mmgen/proto/eth/tx/new.py b/mmgen/proto/eth/tx/new.py index 1b71de2c..28e8444f 100755 --- a/mmgen/proto/eth/tx/new.py +++ b/mmgen/proto/eth/tx/new.py @@ -127,7 +127,7 @@ class New(Base,TxBase.New): def convert_and_check_fee(self,fee,desc): abs_fee = self.feespec2abs(fee,None) - if abs_fee == False: + if abs_fee is False: return False elif not self.disable_fee_check and (abs_fee > self.proto.max_tx_fee): msg('{} {c}: {} fee too large (maximum fee: {} {c})'.format( diff --git a/mmgen/protocol.py b/mmgen/protocol.py index be45204e..e4f7b5ef 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -220,7 +220,7 @@ class CoinProtocol(MMGenObject): """ def encode_wif(self,privbytes,pubkey_type,compressed): assert pubkey_type == self.pubkey_type, f'{pubkey_type}: invalid pubkey_type for {self.name} protocol!' - assert compressed == False, f'{self.name} protocol does not support compressed pubkeys!' + assert compressed is False, f'{self.name} protocol does not support compressed pubkeys!' return privbytes.hex() def decode_wif(self,wif): @@ -239,8 +239,8 @@ def init_proto( tokensym = None, need_amt = False ): - assert type(testnet) == bool, 'init_proto_chk1' - assert type(regtest) == bool, 'init_proto_chk2' + assert type(testnet) is bool, 'init_proto_chk1' + assert type(regtest) is bool, 'init_proto_chk2' assert coin or network_id, 'init_proto_chk3' assert not (coin and network_id), 'init_proto_chk4' @@ -248,8 +248,8 @@ def init_proto( coin,network = CoinProtocol.Base.parse_network_id(network_id) elif network: assert network in CoinProtocol.Base.networks, f'init_proto_chk5 - {network!r}: invalid network' - assert testnet == False, 'init_proto_chk6' - assert regtest == False, 'init_proto_chk7' + assert testnet is False, 'init_proto_chk6' + assert regtest is False, 'init_proto_chk7' else: network = 'regtest' if regtest else 'testnet' if testnet else 'mainnet' diff --git a/mmgen/rpc.py b/mmgen/rpc.py index aab4c704..be3b3b8a 100755 --- a/mmgen/rpc.py +++ b/mmgen/rpc.py @@ -34,7 +34,7 @@ auth_data = namedtuple('rpc_auth_data',['user','passwd']) def dmsg_rpc(fs,data=None,is_json=False): msg( - fs if data == None else + fs if data is None else fs.format(pp_fmt(json.loads(data) if is_json else data)) ) @@ -222,7 +222,7 @@ class RPCBackends: yield s if caller.auth_type == 'digest': yield '--digest' - if caller.network_proto == 'https' and caller.verify_server == False: + if caller.network_proto == 'https' and caller.verify_server is False: yield '--insecure' super().__init__(caller) @@ -338,7 +338,7 @@ class RPCClient(MMGenObject): 1) method = methodname, args_list = [args_tuple1, args_tuple2,...] 2) method = None, args_list = [(methodname1,args_tuple1), (methodname2,args_tuple2), ...] """ - cmd_list = args_list if method == None else tuple(zip([method] * len(args_list), args_list)) + cmd_list = args_list if method is None else tuple(zip([method] * len(args_list), args_list)) cur_pos = 0 chunk_size = 1024 diff --git a/mmgen/seedsplit.py b/mmgen/seedsplit.py index 89b26a0d..a81d7686 100755 --- a/mmgen/seedsplit.py +++ b/mmgen/seedsplit.py @@ -199,7 +199,7 @@ class SeedShare(SeedShareBase,SubSeed): @staticmethod def make_subseed_bin(parent_list,idx:int,nonce:int,length:str): seed = parent_list.parent_seed - assert parent_list.have_short == False + assert parent_list.have_short is False assert length == 'long' # field maximums: id_str: none (256 chars), count: 65535 (1024), idx: 65535 (1024), nonce: 65535 (1000) scramble_key = ( diff --git a/mmgen/sha2.py b/mmgen/sha2.py index 9033cf8d..159834d9 100755 --- a/mmgen/sha2.py +++ b/mmgen/sha2.py @@ -74,7 +74,7 @@ class Sha2(object): def __init__(self,message,preprocess=True): 'Use preprocess=False for Sha256Compress' assert isinstance(message,(bytes,bytearray,list)),'message must be of type bytes, bytearray or list' - if self.K == None: + if self.K is None: type(self).initConstants() self.H = list(self.H_init) self.M = message diff --git a/mmgen/subseed.py b/mmgen/subseed.py index c7c801ba..239b26ce 100755 --- a/mmgen/subseed.py +++ b/mmgen/subseed.py @@ -139,7 +139,7 @@ class SubSeedList(MMGenObject): subseed.ss_idx.hl(), )) - if last_idx == None: + if last_idx is None: last_idx = self.len subseed = get_existing_subseed_by_seed_id(sid) @@ -174,7 +174,7 @@ class SubSeedList(MMGenObject): def _generate(self,last_idx=None,last_sid=None): - if last_idx == None: + if last_idx is None: last_idx = self.len first_idx = len(self) + 1 @@ -182,7 +182,7 @@ class SubSeedList(MMGenObject): if first_idx > last_idx: return None - if last_sid != None: + if last_sid is not None: last_sid = SeedID(sid=last_sid) def add_subseed(idx,length): diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index 6fcb6f98..5f4cb1d7 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -266,7 +266,7 @@ class TwAddresses(TwView): yield (sid_save, sid_range(bot, n-1)) assert self.sort_key == 'twmmid' - assert self.reverse == False + assert self.reverse is False if not hasattr(self,'_sid_ranges'): self._sid_ranges = dict(gen_sid_ranges()) @@ -311,7 +311,7 @@ class TwAddresses(TwView): n = (top + bot) >> 1 assert self.sort_key == 'twmmid' - assert self.reverse == False + assert self.reverse is False data = self.data start = get_start( diff --git a/mmgen/tw/ctl.py b/mmgen/tw/ctl.py index b48f0db1..9b055138 100755 --- a/mmgen/tw/ctl.py +++ b/mmgen/tw/ctl.py @@ -175,7 +175,7 @@ class TwCtl(MMGenObject,metaclass=AsyncInit): async def get_balance(self,addr,force_rpc=False): ret = None if force_rpc else self.get_cached_balance(addr,self.cur_balances,self.data_root) - if ret == None: + if ret is None: ret = await self.rpc_get_balance(addr) self.cache_balance(addr,ret,self.cur_balances,self.data_root) return ret @@ -264,7 +264,7 @@ class TwCtl(MMGenObject,metaclass=AsyncInit): comment = get_obj(TwComment,s=comment) - if comment == False: + if comment is False: return False lbl = get_obj( @@ -272,7 +272,7 @@ class TwCtl(MMGenObject,metaclass=AsyncInit): proto = self.proto, text = res.twmmid + (' ' + comment if comment else '')) - if lbl == False: + if lbl is False: return False if await self.set_label(res.coinaddr,lbl): diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index 523695f9..768810bc 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -690,7 +690,7 @@ class TwView(MMGenObject,metaclass=AsyncInit): break await asyncio.sleep(0.5) - if parent.scroll and ret == False: + if parent.scroll and ret is False: # error messages could leave screen in messy state, so do complete redraw: msg_r( CUR_HOME + ERASE_ALL + diff --git a/mmgen/tx/base.py b/mmgen/tx/base.py index 3da07460..fc4bef73 100755 --- a/mmgen/tx/base.py +++ b/mmgen/tx/base.py @@ -134,7 +134,7 @@ class Base(MMGenObject): return sum(e.amt for e in self.inputs) def sum_outputs(self,exclude=None): - if exclude == None: + if exclude is None: olist = self.outputs else: olist = self.outputs[:exclude] + self.outputs[exclude+1:] diff --git a/mmgen/tx/bump.py b/mmgen/tx/bump.py index c58a91d0..ff272fb3 100755 --- a/mmgen/tx/bump.py +++ b/mmgen/tx/bump.py @@ -59,15 +59,15 @@ class Bump(Completed,New): chg_idx = self.chg_idx while True: - if init_reply == None: + if init_reply is None: from ..ui import line_input m = 'Choose an output to deduct the fee from (Hit ENTER for the change output): ' reply = line_input( self.cfg, m ) or 'c' else: reply,init_reply = init_reply,None - if chg_idx == None and not is_int(reply): + if chg_idx is None and not is_int(reply): msg('Output must be an integer') - elif chg_idx != None and not is_int(reply) and reply != 'c': + elif chg_idx is not None and not is_int(reply) and reply != 'c': msg("Output must be an integer, or 'c' for the change output") else: idx = chg_idx if reply == 'c' else (int(reply) - 1) diff --git a/mmgen/tx/file.py b/mmgen/tx/file.py index 59d34105..a8fede79 100755 --- a/mmgen/tx/file.py +++ b/mmgen/tx/file.py @@ -83,7 +83,7 @@ class MMGenTxFile(MMGenObject): desc = 'encoded comment (not base58)' from ..baseconv import baseconv comment = baseconv('b58').tobytes(c).decode() - assert comment != False,'invalid comment' + assert comment is not False,'invalid comment' desc = 'comment' tx.comment = MMGenTxComment(comment) @@ -197,7 +197,7 @@ class MMGenTxFile(MMGenObject): ask_tty = True, ask_overwrite = True ): - if ask_write == False: + if ask_write is False: ask_write_default_yes = True if not self.filename: diff --git a/mmgen/tx/sign.py b/mmgen/tx/sign.py index 9e2d7f27..4d7d959e 100755 --- a/mmgen/tx/sign.py +++ b/mmgen/tx/sign.py @@ -38,7 +38,7 @@ def get_seed_for_seed_id(sid,infiles,saved_seeds): while True: if infiles: seed = Wallet(cfg,infiles.pop(0),ignore_in_fmt=True).seed - elif subseeds_checked == False: + elif subseeds_checked is False: seed = saved_seeds[list(saved_seeds)[0]].subseed_by_seed_id(sid,print_msg=True) subseeds_checked = True if not seed: diff --git a/mmgen/util.py b/mmgen/util.py index e73665a8..13ef7e5a 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -324,11 +324,11 @@ def decode_timestamp(s): def make_timestamp(secs=None): return '{:04d}{:02d}{:02d}_{:02d}{:02d}{:02d}'.format(*time.gmtime( - int(secs) if secs != None else time.time() )[:6]) + int(secs) if secs is not None else time.time() )[:6]) def make_timestr(secs=None): return '{}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}'.format(*time.gmtime( - int(secs) if secs != None else time.time() )[:6]) + int(secs) if secs is not None else time.time() )[:6]) def secs_to_dhms(secs): hrs = secs // 3600 diff --git a/mmgen/util2.py b/mmgen/util2.py index b6e7c4b9..8d70392b 100755 --- a/mmgen/util2.py +++ b/mmgen/util2.py @@ -137,7 +137,7 @@ def block_format(data,gw=2,cols=8,line_nums=None,data_is_hex=False): gw *= 2 nchunks = len(data)//gw + bool(len(data)%gw) return ''.join( - ('' if (line_nums == None or i % cols) else ln_fs.format(i*bytes_per_chunk)) + ('' if (line_nums is None or i % cols) else ln_fs.format(i*bytes_per_chunk)) + data[i*gw:i*gw+gw] + (' ' if (not cols or (i+1) % cols) else '\n') for i in range(nchunks) diff --git a/mmgen/wallet/mmgen.py b/mmgen/wallet/mmgen.py index edc151c6..44b5db2c 100755 --- a/mmgen/wallet/mmgen.py +++ b/mmgen/wallet/mmgen.py @@ -155,7 +155,7 @@ class wallet(wallet): return False val = baseconv('b58').tobytes(b58_val,pad='seed') - if val == False: + if val is False: msg(f'Invalid base 58 number: {b58_val}') return False diff --git a/mmgen/wallet/seed.py b/mmgen/wallet/seed.py index b58032b8..5a50d1eb 100755 --- a/mmgen/wallet/seed.py +++ b/mmgen/wallet/seed.py @@ -55,7 +55,7 @@ class wallet(wallet): ret = baseconv('b58').tobytes(b,pad='seed') - if ret == False: + if ret is False: msg(f'Invalid base-58 encoded seed: {val}') return False diff --git a/mmgen/xmrseed.py b/mmgen/xmrseed.py index fa9ed164..b74e1063 100755 --- a/mmgen/xmrseed.py +++ b/mmgen/xmrseed.py @@ -48,7 +48,7 @@ class xmrseed(baseconv): def tobytes(self,words,pad=None): assert isinstance(words,(list,tuple)),'words must be list or tuple' - assert pad == None, f"{pad}: invalid 'pad' argument (must be None)" + assert pad is None, f"{pad}: invalid 'pad' argument (must be None)" desc = self.desc.short wl = self.digits @@ -75,7 +75,7 @@ class xmrseed(baseconv): return b''.join(gen()) def frombytes(self,bytestr,pad=None,tostr=False): - assert pad == None, f"{pad}: invalid 'pad' argument (must be None)" + assert pad is None, f"{pad}: invalid 'pad' argument (must be None)" desc = self.desc.short wl = self.digits diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index 0cd991b6..a234d25a 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -1396,7 +1396,7 @@ class MoneroWalletOps: def gen(): for i,k in self.spec_key: - if m[i] == None: + if m[i] is None: setattr(self,k,None) else: idx = int(m[i]) @@ -1463,7 +1463,7 @@ class MoneroWalletOps: gmsg(f'\n{self.stem.capitalize()}ing account #{self.account} of wallet {self.source.idx}' + ( f': {self.amount} XMR to {self.dest_addr}' if self.name == 'transfer' - else ' to new address' if self.dest == None + else ' to new address' if self.dest is None else f' to new account in wallet {self.dest.idx}' )) h = self.rpc(self,self.source) @@ -1479,7 +1479,7 @@ class MoneroWalletOps: if self.name == 'transfer': dest_addr = self.dest_addr - elif self.dest == None: + elif self.dest is None: dest_acct = self.account if keypress_confirm( self.cfg, f'\nCreate new address for account #{self.account}?' ): dest_addr_chk = h.create_new_addr(self.account) @@ -1556,9 +1556,9 @@ class MoneroWalletOps: h = self.rpc(self,self.source) h.open_wallet('Monero') label = '{a} [{b}]'.format( - a = self.label or f"xmrwallet new {'account' if self.account == None else 'address'}", + a = self.label or f"xmrwallet new {'account' if self.account is None else 'address'}", b = make_timestr() ) - if self.account == None: + if self.account is None: acct,addr = h.create_acct(label=label) else: msg_r(f'\n Account index: {pink(str(self.account))}') @@ -1566,7 +1566,7 @@ class MoneroWalletOps: accts_data = h.get_accts()[0] - if self.account != None: + if self.account is not None: h.print_addrs(accts_data,self.account) # wallet must be left open: otherwise the 'stop_wallet' RPC call used to stop the daemon will fail