ruff RUF015 (prefer next(...) over single element slice)
This commit is contained in:
parent
c6ede7eaad
commit
5ccf9e061e
15 changed files with 20 additions and 21 deletions
|
|
@ -51,7 +51,7 @@ class AddrData(MMGenObject):
|
|||
|
||||
def coinaddr2mmaddr(self, coinaddr):
|
||||
d = self.make_reverse_dict([coinaddr])
|
||||
return (list(d.values())[0][0]) if d else None
|
||||
return next(iter(d.values()))[0] if d else None
|
||||
|
||||
def add(self, addrlist):
|
||||
if isinstance(addrlist, AddrList):
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ def get_terminfo_colors(term=None):
|
|||
return None
|
||||
else:
|
||||
set_vt100()
|
||||
s = [e.split('#')[1] for e in cmdout.split(',') if e.startswith('colors')][0]
|
||||
s = next(iter(e.split('#', 1)[1] for e in cmdout.split(',') if e.startswith('colors')))
|
||||
from .util import is_hex_str
|
||||
if s.isdecimal():
|
||||
return int(s)
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ class Daemon(Lockable):
|
|||
die(2, f'Unable to execute {cls.exec_fn}')
|
||||
else:
|
||||
res = cp.stdout.splitlines()
|
||||
return (res[0] if len(res) == 1 else [s for s in res if 'ersion' in s][0]).strip()
|
||||
return (res[0] if len(res) == 1 else next(s for s in res if 'ersion' in s)).strip()
|
||||
|
||||
class RPCDaemon(Daemon):
|
||||
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ class BitcoinRPCClient(RPCClient, metaclass=AsyncInit):
|
|||
self.daemon.cfg_file)
|
||||
|
||||
def get_daemon_cfg_option(self, req_key):
|
||||
return list(self.get_daemon_cfg_options([req_key]).values())[0]
|
||||
return next(iter(self.get_daemon_cfg_options([req_key]).values()))
|
||||
|
||||
def get_daemon_cfg_options(self, req_keys):
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class CoinProtocol(MMGenObject):
|
|||
if hasattr(self, 'addr_ver_info'):
|
||||
self.addr_ver_bytes = {bytes.fromhex(k): v for k, v in self.addr_ver_info.items()}
|
||||
self.addr_fmt_to_ver_bytes = {v: k for k, v in self.addr_ver_bytes.items()}
|
||||
self.addr_ver_bytes_len = len(list(self.addr_ver_bytes)[0])
|
||||
self.addr_ver_bytes_len = len(next(iter(self.addr_ver_bytes)))
|
||||
|
||||
if gc.cmd_caps:
|
||||
for cap in gc.cmd_caps.caps:
|
||||
|
|
|
|||
|
|
@ -673,7 +673,7 @@ class TwView(MMGenObject, metaclass=AsyncInit):
|
|||
async def do_error_msg():
|
||||
msg_r(
|
||||
'Choice must be a single number between {n} and {m} inclusive{s}'.format(
|
||||
n = list(data.keys())[0] if is_addr_idx else 1,
|
||||
n = next(iter(data.keys())) if is_addr_idx else 1,
|
||||
m = list(data.keys())[-1] if is_addr_idx else len(data),
|
||||
s = ' ' if self.scroll else ''))
|
||||
if self.scroll:
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ class TxKeys:
|
|||
ignore_in_fmt = True,
|
||||
passwd_file = self.passwdfile).seed
|
||||
elif self.saved_seeds and subseeds_checked is False:
|
||||
seed = self.saved_seeds[list(self.saved_seeds)[0]].subseed_by_seed_id(sid, print_msg=True)
|
||||
seed = self.saved_seeds[next(iter(self.saved_seeds))].subseed_by_seed_id(sid, print_msg=True)
|
||||
subseeds_checked = True
|
||||
if not seed:
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ ignore = [
|
|||
"PLW1510", # `subprocess.run` without explicit `check` argument
|
||||
"RET501", # Do not explicitly `return None` in function if it is the only possible return value
|
||||
"RUF012", # Mutable default value for class attribute
|
||||
"RUF015", # Prefer `next(s for s in res if 'ersion' in s)` over single element slice
|
||||
"RUF022", # `__all__` is not sorted
|
||||
"RUF100", # Unused `noqa` directive (non-enabled: `F401`)
|
||||
"S102", # Use of `exec` detected
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class EtherscanServer(HTTPD):
|
|||
target = 'result'
|
||||
length = int(environ.get('CONTENT_LENGTH', '0'))
|
||||
qs = environ['wsgi.input'].read(length).decode()
|
||||
tx = [s for s in qs.split('&') if 'RawTx=' in s][0].split('=')[1]
|
||||
tx = next(s for s in qs.split('&') if 'RawTx=' in s).split('=')[1]
|
||||
keccak_256 = get_keccak()
|
||||
txid = '0x' + keccak_256(bytes.fromhex(tx[2:])).hexdigest()
|
||||
|
||||
|
|
|
|||
|
|
@ -1510,7 +1510,7 @@ class CmdTestRegtest(CmdTestBase, CmdTestShared):
|
|||
assert self.proto.cap('segwit')
|
||||
if not hasattr(self, '_b_start_'):
|
||||
t = self.spawn('mmgen-tool', ['--color=0', '--bob', 'listaddresses'], no_msg=True)
|
||||
self._b_start_ = int([e for e in t.read().split('\n') if ':B:1' in e][0].split()[0].rstrip(')'))
|
||||
self._b_start_ = int(next(e for e in t.read().split('\n') if ':B:1' in e).split(maxsplit=1)[0].rstrip(')'))
|
||||
t.close()
|
||||
return self._b_start_
|
||||
|
||||
|
|
@ -1677,7 +1677,7 @@ class CmdTestRegtest(CmdTestBase, CmdTestShared):
|
|||
def alice_add_comment_coinaddr(self):
|
||||
mmid = self._user_sid('alice') + (':S:1', ':L:1')[self.proto.coin=='BCH']
|
||||
t = self.spawn('mmgen-tool', ['--alice', 'listaddress', mmid, 'wide=true'], no_msg=True)
|
||||
addr = [i for i in strip_ansi_escapes(t.read()).splitlines() if re.search(rf'\b{mmid}\b', i)][0].split()[3]
|
||||
addr = next(i for i in strip_ansi_escapes(t.read()).splitlines() if re.search(rf'\b{mmid}\b', i)).split()[3]
|
||||
return self.user_add_comment('alice', addr, 'Label added using coin address of MMGen address')
|
||||
|
||||
def alice_chk_comment_coinaddr(self):
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class CmdTestShared:
|
|||
e2 = fr'Using .*{auto_chg_addr}.* as.*address'
|
||||
res = t.expect([e1, e2], regex=True)
|
||||
if res == 0:
|
||||
choice = [s.split(')')[0].lstrip() for s in t.p.match[0].split('\n') if auto_chg_addr in s][0]
|
||||
choice = next(s.split(')', 1)[0].lstrip() for s in t.p.match[0].split('\n') if auto_chg_addr in s)
|
||||
t.send(f'{choice}\n')
|
||||
t.expect(e2, regex=True)
|
||||
t.send('y')
|
||||
|
|
|
|||
|
|
@ -581,7 +581,7 @@ class CmdTestSwap(CmdTestSwapMethods, CmdTestRegtest, CmdTestAutosignThreaded):
|
|||
def fund_bob_recv_subwallet(self, proto_idx=1, amt='5'):
|
||||
coin_arg = f'--coin={self.protos[proto_idx].coin}'
|
||||
t = self.spawn('mmgen-tool', ['--bob', coin_arg, 'listaddresses'])
|
||||
addr = [s for s in strip_ansi_escapes(t.read()).splitlines() if 'C:1 No' in s][0].split()[3]
|
||||
addr = next(s for s in strip_ansi_escapes(t.read()).splitlines() if 'C:1 No' in s).split()[3]
|
||||
t = self.spawn(
|
||||
'mmgen-regtest',
|
||||
[coin_arg, 'send', addr, str(amt)],
|
||||
|
|
|
|||
|
|
@ -63,14 +63,14 @@ class unit_tests:
|
|||
assert len(s_lines) == nSubseeds + 4, s
|
||||
|
||||
a = seed.subseed('2L').sid
|
||||
b = [e for e in s_lines if ' 2L:' in e][0].strip().split()[1]
|
||||
b = next(e for e in s_lines if ' 2L:' in e).strip().split()[1]
|
||||
assert a == b, b
|
||||
|
||||
c = seed.subseed('2').sid
|
||||
assert c == a, c
|
||||
|
||||
a = seed.subseed('5S').sid
|
||||
b = [e for e in s_lines if ' 5S:' in e][0].strip().split()[3]
|
||||
b = next(e for e in s_lines if ' 5S:' in e).strip().split()[3]
|
||||
assert a == b, b
|
||||
|
||||
s = seed.subseeds.format(nSubseeds+1, nSubseeds+2)
|
||||
|
|
@ -79,7 +79,7 @@ class unit_tests:
|
|||
|
||||
ss_idx = str(nSubseeds+2) + 'S'
|
||||
a = seed.subseed(ss_idx).sid
|
||||
b = [e for e in s_lines if f' {ss_idx}:' in e][0].strip().split()[3]
|
||||
b = next(e for e in s_lines if f' {ss_idx}:' in e).strip().split()[3]
|
||||
assert a == b, b
|
||||
|
||||
s = seed.subseeds.format(1, 10)
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ class unit_tests:
|
|||
|
||||
}
|
||||
|
||||
col1_w = max(len(str(e)) for e in list(chks.values())[0]) + 1
|
||||
col1_w = max(len(str(e)) for e in next(iter(chks.values()))) + 1
|
||||
|
||||
for _name, sample in samples.items():
|
||||
vmsg(cyan(f'Input: {sample}'))
|
||||
for fmt in list(chks.values())[0]:
|
||||
for fmt in next(iter(chks.values())):
|
||||
spc = '\n' if fmt in ('col', 'list') else ' '
|
||||
indent = ' + ' if fmt == 'col' else ''
|
||||
res = fmt_list(sample, fmt=fmt, indent=indent) if fmt else fmt_list(sample, indent=indent)
|
||||
|
|
@ -82,11 +82,11 @@ class unit_tests:
|
|||
}
|
||||
}
|
||||
|
||||
col1_w = max(len(str(e)) for e in list(chks.values())[0]) + 1
|
||||
col1_w = max(len(str(e)) for e in next(iter(chks.values()))) + 1
|
||||
|
||||
for _name, sample in samples.items():
|
||||
vmsg(cyan(f'Input: {sample}'))
|
||||
for fmt in list(chks.values())[0]:
|
||||
for fmt in next(iter(chks.values())):
|
||||
res = fmt_dict(sample, fmt=fmt) if fmt else fmt_dict(sample)
|
||||
vmsg(f' {str(fmt)+":":{col1_w}} {res}')
|
||||
if _name in chks:
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ def run_test(mod, test, arg, input_data, arg1, exc_name):
|
|||
del arg['arg']
|
||||
else:
|
||||
args = []
|
||||
ret_chk = list(arg.values())[0] # assume only one key present
|
||||
ret_chk = next(iter(arg.values())) # assume only one key present
|
||||
if 'ret' in arg:
|
||||
ret_chk = arg['ret']
|
||||
del arg['ret']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue