isinstance(): use type union operator (11 files changed)
This commit is contained in:
parent
28c39f2b5f
commit
d13baa1a07
11 changed files with 12 additions and 12 deletions
|
|
@ -111,7 +111,7 @@ class AddrListID(HiliteStr, InitErrors, MMGenObject):
|
|||
mmtype = MMGenPasswordType(proto=proto, id_str=b)
|
||||
else:
|
||||
assert isinstance(sid, SeedID), f'{sid!r} not a SeedID instance'
|
||||
if not isinstance(mmtype, (MMGenAddrType, MMGenPasswordType)):
|
||||
if not isinstance(mmtype, MMGenAddrType | MMGenPasswordType):
|
||||
raise ValueError(f'{mmtype!r}: not an instance of MMGenAddrType or MMGenPasswordType')
|
||||
me = str.__new__(cls, sid+':'+mmtype)
|
||||
me.sid = sid
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ class baseconv:
|
|||
def tobytes(self, words_arg, /, *, pad=None):
|
||||
"convert string or list data of instance base to byte string"
|
||||
|
||||
words = words_arg if isinstance(words_arg, (list, tuple)) else tuple(words_arg.strip())
|
||||
words = words_arg if isinstance(words_arg, list | tuple) else tuple(words_arg.strip())
|
||||
desc = self.desc.short
|
||||
|
||||
if len(words) == 0:
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class bip39(baseconv):
|
|||
return self.tobytes(words_arg, pad=pad).hex()
|
||||
|
||||
def tobytes(self, words_arg, /, *, pad=None):
|
||||
assert isinstance(words_arg, (list, tuple)), 'words_arg must be list or tuple'
|
||||
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
|
||||
|
|
|
|||
|
|
@ -987,11 +987,11 @@ def conv_type(name, val, refval, *, src, invert_bool=False):
|
|||
None
|
||||
)
|
||||
return do_fail() if ret is None else (not ret) if invert_bool else ret
|
||||
elif isinstance(refval, (list, tuple)):
|
||||
elif isinstance(refval, list | tuple):
|
||||
if src == 'cmdline':
|
||||
return type(refval)(val.split(','))
|
||||
else:
|
||||
assert isinstance(val, (list, tuple)), f'{val}: not a list or tuple'
|
||||
assert isinstance(val, list | tuple), f'{val}: not a list or tuple'
|
||||
return type(refval)(val)
|
||||
else:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class cfg_file:
|
|||
m = re.fullmatch(r'((\s+\w+:\S+)+)', ' '+value) # expect one or more colon-separated values
|
||||
if m:
|
||||
return dict([i.split(':') for i in m[1].split()])
|
||||
elif isinstance(refval, (list, tuple)):
|
||||
elif isinstance(refval, list | tuple):
|
||||
m = re.fullmatch(r'((\s+\S+)+)', ' '+value) # expect single value or list
|
||||
if m:
|
||||
ret = m[1].split()
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class Sha2:
|
|||
|
||||
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'
|
||||
assert isinstance(message, bytes | bytearray | list), 'message must be of type bytes, bytearray or list'
|
||||
if not self.K:
|
||||
type(self).initConstants()
|
||||
self.H = list(self.H_init)
|
||||
|
|
|
|||
|
|
@ -425,7 +425,7 @@ class TwAddresses(TwView):
|
|||
f'{sid}:{mmtype}', bot=r.bot, top=r.top, exclude=exclude, desc=desc)
|
||||
for sid, r in self.sid_ranges.items()]
|
||||
|
||||
assert isinstance(mmtype, (type(None), MMGenAddrType))
|
||||
assert isinstance(mmtype, type(None) | MMGenAddrType)
|
||||
|
||||
if mmtype:
|
||||
res = get_addr(mmtype)
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ class New(Base):
|
|||
|
||||
async def create(self, cmd_args, *, locktime=None, do_info=False, caller='txcreate'):
|
||||
|
||||
assert isinstance(locktime, (int, type(None))), 'locktime must be of type int'
|
||||
assert isinstance(locktime, int | type(None)), 'locktime must be of type int'
|
||||
|
||||
from ..tw.unspent import TwUnspentOutputs
|
||||
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ def suf(arg, suf_type='s', *, verb='none'):
|
|||
}
|
||||
if isinstance(arg, int):
|
||||
n = arg
|
||||
elif isinstance(arg, (list, tuple, set, dict)):
|
||||
elif isinstance(arg, list | tuple | set | dict):
|
||||
n = len(arg)
|
||||
else:
|
||||
die(2, f'{arg}: invalid parameter for suf()')
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class xmrseed(baseconv):
|
|||
|
||||
def tobytes(self, words_arg, *, pad=None):
|
||||
|
||||
assert isinstance(words_arg, (list, tuple)), 'words must be list or tuple'
|
||||
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
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ def run_test(cls, gid, cmd_name):
|
|||
cmd_out,
|
||||
out[1],
|
||||
func_out))
|
||||
elif isinstance(out, (list, tuple)):
|
||||
elif isinstance(out, list | tuple):
|
||||
for co, o in zip(cmd_out.split(NL) if cfg.fork else cmd_out, out):
|
||||
check_output(co, o)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue