From 055759f02a5eaac9efdff85208a5b7e8141d07bd Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 13 Oct 2023 09:51:13 +0000 Subject: [PATCH] pylint integration: minor compatibility changes --- mmgen/fileutil.py | 8 ++++---- mmgen/proto/eth/tx/completed.py | 2 ++ mmgen/protocol.py | 5 +++-- mmgen/pyversion.py | 3 +++ mmgen/sha2.py | 4 ++-- mmgen/tx/file.py | 2 +- mmgen/xmrwallet.py | 7 +++++++ test/colortest.py | 1 + test/hashfunc.py | 1 + test/objtest.py | 1 + test/test.py | 2 ++ test/unit_tests_d/ut_devtools.py | 1 + test/unit_tests_d/ut_tx.py | 1 + test/unit_tests_d/ut_tx_deserialize.py | 1 + 14 files changed, 30 insertions(+), 9 deletions(-) diff --git a/mmgen/fileutil.py b/mmgen/fileutil.py index 2d77fb94..ce470f6f 100755 --- a/mmgen/fileutil.py +++ b/mmgen/fileutil.py @@ -243,14 +243,14 @@ def write_data_to_file( # not atomic, but better than nothing # if cmp_data is empty, file can be either empty or non-existent if check_data: + d = '' try: with open(outfile,('r','rb')[bool(binary)]) as fp: d = fp.read() except: - d = '' - finally: - if d != cmp_data: - die(3,f'{desc} in file {outfile!r} has been altered by some other program! Aborting file write') + pass + if d != cmp_data: + die(3,f'{desc} in file {outfile!r} has been altered by some other program! Aborting file write') # To maintain portability, always open files in binary mode # If 'binary' option not set, encode/decode data before writing and after reading diff --git a/mmgen/proto/eth/tx/completed.py b/mmgen/proto/eth/tx/completed.py index 4f001ac9..47d8550e 100755 --- a/mmgen/proto/eth/tx/completed.py +++ b/mmgen/proto/eth/tx/completed.py @@ -20,6 +20,8 @@ class Completed(Base,TxBase.Completed): def __init__(self,*args,**kwargs): + self.txobj = {} + super().__init__(*args,**kwargs) self.gas = self.proto.coin_amt(self.dfl_gas,'wei') diff --git a/mmgen/protocol.py b/mmgen/protocol.py index 59764389..782f9567 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -52,6 +52,7 @@ class CoinProtocol(MMGenObject): base_proto_coin = None base_coin = None is_fork_of = None + chain_names = None networks = ('mainnet','testnet','regtest') def __init__(self,cfg,coin,name,network,tokensym=None,need_amt=False): @@ -86,11 +87,11 @@ class CoinProtocol(MMGenObject): from .util import die die(2,f'Command {gc.prog_name!r} not supported for coin {self.coin}') - if hasattr(self,'chain_names'): + if self.chain_names: self.chain_name = self.chain_names[0] # first chain name is default else: - self.chain_name = self.network self.chain_names = [self.network] + self.chain_name = self.network if self.tokensym: assert self.name.startswith('Ethereum'), 'CoinProtocol.Base_chk1' diff --git a/mmgen/pyversion.py b/mmgen/pyversion.py index cfab1720..b91d291c 100755 --- a/mmgen/pyversion.py +++ b/mmgen/pyversion.py @@ -14,6 +14,9 @@ pyversion: Python version string operations class PythonVersion(str): + major = 0 + minor = 0 + def __new__(cls,arg=None): if isinstance(arg,PythonVersion): return arg diff --git a/mmgen/sha2.py b/mmgen/sha2.py index 0f000d64..577ca6b2 100755 --- a/mmgen/sha2.py +++ b/mmgen/sha2.py @@ -31,7 +31,7 @@ from struct import pack,unpack class Sha2: 'Implementation based on the pseudocode at https://en.wikipedia.org/wiki/SHA-2' - K = None + K = () @classmethod def initConstants(cls): @@ -71,7 +71,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' - if self.K is None: + if not self.K: type(self).initConstants() self.H = list(self.H_init) self.M = message diff --git a/mmgen/tx/file.py b/mmgen/tx/file.py index be23ba29..e9a8e5da 100755 --- a/mmgen/tx/file.py +++ b/mmgen/tx/file.py @@ -60,8 +60,8 @@ class MMGenTxFile(MMGenObject): from ..fileutil import get_data_from_file tx_data = get_data_from_file( tx.cfg, infile, tx.desc+' data', quiet=quiet_open ) + desc = 'data' try: - desc = 'data' if len(tx_data) > tx.cfg.max_tx_file_size: die('MaxFileSizeExceeded', f'Transaction file size exceeds limit ({tx.cfg.max_tx_file_size} bytes)') diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index 06a80cd6..81fd1811 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -76,6 +76,13 @@ xmrwallet_uarg_info = ( r'(?:[^:]+):(?:\d+)' ) +# required to squelch pylint: +def fmt_amt(amt): + return str(amt) + +def hl_amt(amt): + return str(amt) + class XMRWalletAddrSpec(HiliteStr,InitErrors,MMGenObject): color = 'cyan' width = 0 diff --git a/test/colortest.py b/test/colortest.py index 87265d4a..99eed61d 100755 --- a/test/colortest.py +++ b/test/colortest.py @@ -29,6 +29,7 @@ def test_color(): init_color() gmsg("\nParsed terminfo 'colors' values:") + from mmgen.color import orange for t,c in (('rxvt',8),('xterm',8),('rxvt-unicode',88),('screen-256color',256),('xterm-256color',256)): ret = get_terminfo_colors(t) if ret is None: diff --git a/test/hashfunc.py b/test/hashfunc.py index 480edb0e..e1dedf1e 100755 --- a/test/hashfunc.py +++ b/test/hashfunc.py @@ -129,6 +129,7 @@ class TestKeccak(TestHashFunc): pass class TestSha2(TestHashFunc): + desc = 'sha2' def __init__(self): from mmgen.sha2 import Sha256,Sha512 diff --git a/test/objtest.py b/test/objtest.py index 2d9e690f..040c44d5 100755 --- a/test/objtest.py +++ b/test/objtest.py @@ -26,6 +26,7 @@ import include.test_init # for objtest, violate MMGen Project best practices and allow use of the dev tools # in production code: +from mmgen.devtools import pmsg if not os.getenv('MMGEN_DEVTOOLS'): from mmgen.devinit import init_dev init_dev() diff --git a/test/test.py b/test/test.py index e092274e..e2d9bf04 100755 --- a/test/test.py +++ b/test/test.py @@ -369,6 +369,8 @@ def set_restore_term_at_exit(): class CmdGroupMgr: + dpy_data = None + from test.test_py_d.cfg import cmd_groups_dfl,cmd_groups_extra cmd_groups = cmd_groups_dfl.copy() diff --git a/test/unit_tests_d/ut_devtools.py b/test/unit_tests_d/ut_devtools.py index 4a6f4217..b05ad1ea 100755 --- a/test/unit_tests_d/ut_devtools.py +++ b/test/unit_tests_d/ut_devtools.py @@ -6,6 +6,7 @@ test.unit_tests_d.ut_devtools: devtools unit tests for the MMGen suite import os,json from mmgen.util import msg +from mmgen.devtools import print_diff,get_ndiff,print_stack_trace,pmsg_r,pmsg,Pmsg from . import unit_tests_base textA = """ diff --git a/test/unit_tests_d/ut_tx.py b/test/unit_tests_d/ut_tx.py index 15e8fd2f..75c0806d 100755 --- a/test/unit_tests_d/ut_tx.py +++ b/test/unit_tests_d/ut_tx.py @@ -6,6 +6,7 @@ test.unit_tests_d.ut_tx: TX unit tests for the MMGen suite import os,re +from mmgen.devtools import get_diff,get_ndiff from mmgen.tx import NewTX,CompletedTX from mmgen.tx.file import MMGenTxFile from mmgen.daemon import CoinDaemon diff --git a/test/unit_tests_d/ut_tx_deserialize.py b/test/unit_tests_d/ut_tx_deserialize.py index 7528f282..338bf76a 100755 --- a/test/unit_tests_d/ut_tx_deserialize.py +++ b/test/unit_tests_d/ut_tx_deserialize.py @@ -8,6 +8,7 @@ import os,json from mmgen.color import purple,cyan from mmgen.util import msg,Msg,Msg_r +from mmgen.devtools import Pmsg from mmgen.protocol import init_proto from mmgen.tx import CompletedTX from mmgen.proto.btc.tx.base import DeserializeTX