ruff B023 (function definition in loop)
This commit is contained in:
parent
f311f46840
commit
a75234bb9e
3 changed files with 47 additions and 42 deletions
|
|
@ -99,33 +99,37 @@ class TxInfo(TxInfo):
|
|||
if have_bch and e.addr:
|
||||
yield '{:3} [{}]\n'.format('', e.addr.hl(vp2, color=False))
|
||||
else:
|
||||
col1_w = len(str(len(io))) + 1
|
||||
for n, e in enumerate(io_sorted()):
|
||||
def gen(n, e):
|
||||
mmid_fmt = get_mmid_fmt(e, is_input)
|
||||
if is_input:
|
||||
yield (n+1, 'tx,vout:', f'{e.txid.hl()},{red(str(e.vout))}')
|
||||
yield ('', 'address:', f'{e.addr.hl(vp1)} {mmid_fmt}')
|
||||
if have_bch:
|
||||
yield ('', '', f'[{e.addr.hl(vp2, color=False)}]')
|
||||
else:
|
||||
yield (
|
||||
n + 1,
|
||||
'address:',
|
||||
(f'{e.addr.hl(vp1)} {mmid_fmt}' if e.addr else e.data.hl(add_label=True)))
|
||||
if have_bch and e.addr:
|
||||
yield ('', '', f'[{e.addr.hl(vp2, color=False)}]')
|
||||
|
||||
if e.comment:
|
||||
yield ('', 'comment:', e.comment.hl())
|
||||
|
||||
yield ('', 'amount:', f'{e.amt.hl()} {tx.dcoin}')
|
||||
|
||||
if is_input and blockcount:
|
||||
confs = e.confs + blockcount - tx.blockcount
|
||||
days = int(confs // confs_per_day)
|
||||
def gen():
|
||||
if is_input:
|
||||
yield (n+1, 'tx,vout:', f'{e.txid.hl()},{red(str(e.vout))}')
|
||||
yield ('', 'address:', f'{e.addr.hl(vp1)} {mmid_fmt}')
|
||||
if have_bch:
|
||||
yield ('', '', f'[{e.addr.hl(vp2, color=False)}]')
|
||||
else:
|
||||
yield (
|
||||
n + 1,
|
||||
'address:',
|
||||
(f'{e.addr.hl(vp1)} {mmid_fmt}' if e.addr else e.data.hl(add_label=True)))
|
||||
if have_bch and e.addr:
|
||||
yield ('', '', f'[{e.addr.hl(vp2, color=False)}]')
|
||||
if e.comment:
|
||||
yield ('', 'comment:', e.comment.hl())
|
||||
yield ('', 'amount:', f'{e.amt.hl()} {tx.dcoin}')
|
||||
if is_input and blockcount:
|
||||
yield ('', 'confirmations:', f'{confs} (around {days} days)')
|
||||
if not is_input and e.is_chg:
|
||||
yield ('', 'change:', green('True'))
|
||||
yield '\n'.join('{:>{w}} {:<8} {}'.format(*d, w=col1_w) for d in gen()) + '\n\n'
|
||||
yield ('', 'confirmations:', f'{confs} (around {confs // confs_per_day} days)')
|
||||
|
||||
if not is_input and e.is_chg:
|
||||
yield ('', 'change:', green('True'))
|
||||
|
||||
col1_w = len(str(len(io))) + 1
|
||||
|
||||
for n, e in enumerate(io_sorted()):
|
||||
yield '\n'.join('{:>{w}} {:<8} {}'.format(*d, w=col1_w) for d in gen(n, e)) + '\n\n'
|
||||
|
||||
tx = self.tx
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ ignore = [
|
|||
"ASYNC221", # blocking method in async function (mmgen/rpc/backends/curl.py)
|
||||
"B006", # Do not use mutable data structures for argument defaults
|
||||
"B018", # Found useless expression. Either assign it to a variable or remove it.
|
||||
"B023", # Function definition does not bind loop variable `confs`
|
||||
"B026", # Star-arg unpacking after a keyword argument is strongly discouraged
|
||||
"BLE001", # Do not catch blind exception: `Exception`
|
||||
"C401", # Unnecessary generator (rewrite as a set comprehension)
|
||||
|
|
|
|||
|
|
@ -81,6 +81,24 @@ class unit_tests:
|
|||
|
||||
def memo(self, name, ut, desc='Swap transaction memo'):
|
||||
|
||||
def bad(s):
|
||||
return lambda: Memo.parse(s)
|
||||
|
||||
def bad10(swap_cfg):
|
||||
def inner():
|
||||
coin = 'BTC'
|
||||
proto = init_proto(cfg, coin, need_amt=True)
|
||||
addr = make_burn_addr(proto, 'C')
|
||||
asset = SwapAsset(coin, 'send')
|
||||
Memo(swap_cfg, proto, asset, addr, trade_limit=None)
|
||||
return inner
|
||||
|
||||
def bad11():
|
||||
SwapAsset('XYZ', 'send')
|
||||
|
||||
def bad12():
|
||||
SwapAsset('DOGE', 'send')
|
||||
|
||||
for coin, addrtype, asset_name, token in (
|
||||
('ltc', 'bech32', 'LTC', None),
|
||||
('bch', 'compressed', 'BCH', None),
|
||||
|
|
@ -158,22 +176,6 @@ class unit_tests:
|
|||
|
||||
vmsg('\nTesting error handling:')
|
||||
|
||||
def bad(s):
|
||||
return lambda: Memo.parse(s)
|
||||
|
||||
def bad10():
|
||||
coin = 'BTC'
|
||||
proto = init_proto(cfg, coin, need_amt=True)
|
||||
addr = make_burn_addr(proto, 'C')
|
||||
asset = SwapAsset(coin, 'send')
|
||||
Memo(swap_cfg, proto, asset, addr, trade_limit=None)
|
||||
|
||||
def bad11():
|
||||
SwapAsset('XYZ', 'send')
|
||||
|
||||
def bad12():
|
||||
SwapAsset('DOGE', 'send')
|
||||
|
||||
ut.process_bad_data((
|
||||
('bad1', 'SwapMemoParseError', 'must contain', bad('x')),
|
||||
('bad2', 'SwapMemoParseError', 'must contain', bad('y:z:x')),
|
||||
|
|
@ -182,7 +184,7 @@ class unit_tests:
|
|||
('bad5', 'SwapMemoParseError', 'failed to parse', bad('=:l:foobar:n')),
|
||||
('bad6', 'SwapMemoParseError', 'invalid specifier', bad('=:l:foobar:x/3/0')),
|
||||
('bad7', 'SwapMemoParseError', 'extra', bad('=:l:foobar:0/3/0:x')),
|
||||
('bad10', 'AssertionError', 'recv', bad10),
|
||||
('bad10', 'AssertionError', 'recv', bad10(swap_cfg)),
|
||||
('bad11', 'SwapAssetError', 'unrecognized', bad11),
|
||||
('bad12', 'SwapAssetError', 'unsupported', bad12),
|
||||
), pfx='')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue