Browse Source

pylint throughout (excluding tests) - string formatting

The MMGen Project 1 year ago
parent
commit
8e13b296fb

+ 4 - 4
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

+ 1 - 3
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):
 

+ 4 - 2
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)
 

+ 4 - 5
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

+ 6 - 1
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'])

+ 1 - 1
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)

+ 3 - 1
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: ',
 				),
 			}

+ 6 - 6
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)
 

+ 8 - 8
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:

+ 7 - 7
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

+ 28 - 28
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')