Repository: randombit/botan
Pull request #3565 (2023-05-30 18:00:51)

Disable noisy/pointless pylint warnings


Patch:
diff --git a/configure.py b/configure.py
index 6c47f1088..b5741ad40 100755
--- a/configure.py
+++ b/configure.py
@@ -1,7 +1,5 @@
 #!/usr/bin/env python3
 
-# pylint: disable=too-many-lines
-
 """
 Configuration program for botan
 
@@ -196,7 +194,7 @@ class SourcePaths:
         self.sphinx_config_dir = os.path.join(self.configs_dir, 'sphinx')
 
 
-class BuildPaths: # pylint: disable=too-many-instance-attributes
+class BuildPaths:
     """
     Constructor
     """
@@ -302,7 +300,7 @@ class BuildPaths: # pylint: disable=too-many-instance-attributes
 
 ACCEPTABLE_BUILD_TARGETS = ["static", "shared", "cli", "tests", "bogo_shim", "examples"]
 
-def process_command_line(args): # pylint: disable=too-many-locals,too-many-statements
+def process_command_line(args):
     """
     Handle command line options
     Do not use logging in this method as command line options need to be
@@ -822,7 +820,6 @@ class ModuleInfo(InfoObject):
     """
 
     def __init__(self, infofile):
-        # pylint: disable=too-many-statements
         super().__init__(infofile)
         lex = lex_me_harder(
             infofile,
@@ -1205,7 +1202,7 @@ class ArchInfo(InfoObject):
         return sorted(isas)
 
 
-class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes
+class CompilerInfo(InfoObject):
     def __init__(self, infofile):
         super().__init__(infofile)
         lex = lex_me_harder(
@@ -1379,7 +1376,6 @@ class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes
         return ''
 
     def mach_abi_link_flags(self, options, debug_mode=None):
-        #pylint: disable=too-many-branches
 
         """
         Return the machine specific ABI flags
@@ -1470,8 +1466,6 @@ class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes
         return self.lang_binary_linker_flags
 
     def cc_compile_flags(self, options, with_debug_info=None, enable_optimizations=None):
-        #pylint: disable=too-many-branches
-
         def gen_flags(with_debug_info, enable_optimizations):
 
             sanitizers_enabled = options.with_sanitizers or (len(options.enable_sanitizers) > 0)
@@ -1545,7 +1539,7 @@ class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes
 
         return '{linker}'
 
-class OsInfo(InfoObject): # pylint: disable=too-many-instance-attributes
+class OsInfo(InfoObject):
     def __init__(self, infofile):
         super().__init__(infofile)
         lex = lex_me_harder(
@@ -1720,8 +1714,6 @@ def read_textfile(filepath):
 
 
 def process_template_string(template_text, variables, template_source):
-    # pylint: disable=too-many-branches,too-many-statements
-
     """
     Perform template substitution
 
@@ -1738,7 +1730,6 @@ def process_template_string(template_text, variables, template_source):
             self.join_pattern = re.compile('%{join ([a-z][a-z_0-9]+)}')
 
         def substitute(self, template):
-            # pylint: disable=too-many-locals
             def insert_value(match):
                 v = match.group(1)
                 if v in self.vals:
@@ -1836,7 +1827,7 @@ def process_template_string(template_text, variables, template_source):
         return SimpleTemplate(variables).substitute(template_text)
     except KeyError as ex:
         logging.error('Unbound var %s in template %s', ex, template_source)
-    except Exception as ex: # pylint: disable=broad-except
+    except Exception as ex:
         logging.error('Exception %s during template processing file %s', ex, template_source)
 
 def process_template(template_file, variables):
@@ -1880,8 +1871,6 @@ def yield_objectfile_list(sources, obj_dir, obj_suffix, options):
         yield normalize_source_path(os.path.join(obj_dir, name))
 
 def generate_build_info(build_paths, modules, cc, arch, osinfo, options):
-    # pylint: disable=too-many-locals
-
     # first create a map of src_file->owning module
 
     module_that_owns = {}
@@ -1969,8 +1958,6 @@ def generate_build_info(build_paths, modules, cc, arch, osinfo, options):
     return out
 
 def create_template_vars(source_paths, build_paths, options, modules, cc, arch, osinfo):
-    #pylint: disable=too-many-locals,too-many-branches,too-many-statements
-
     """
     Create the template variables needed to process the makefile, build.h, etc
     """
@@ -2511,7 +2498,7 @@ class ModulesChooser:
         self._to_load = successfully_loaded
         self._maybe_dep -= successfully_loaded
 
-    def _handle_by_load_on(self, module): # pylint: disable=too-many-branches
+    def _handle_by_load_on(self, module):
         modname = module.basename
         if module.load_on == 'never':
             self._not_using_because['disabled as buggy'].add(modname)
@@ -2950,7 +2937,7 @@ def python_platform_identifier():
 # This is for otions that have --with-XYZ and --without-XYZ. If user does not
 # set any of those, we choose a default here.
 # Mutates `options`
-def set_defaults_for_unset_options(options, info_arch, info_cc, info_os): # pylint: disable=too-many-branches
+def set_defaults_for_unset_options(options, info_arch, info_cc, info_os):
     if options.os is None:
         options.os = python_platform_identifier()
         logging.info('Guessing target OS is %s (use --os to set)', options.os)
@@ -3029,8 +3016,6 @@ def set_defaults_for_unset_options(options, info_arch, info_cc, info_os): # pyli
 
 # Mutates `options`
 def canonicalize_options(options, info_os, info_arch):
-    # pylint: disable=too-many-branches
-
     # canonical ARCH/CPU
     options.arch = canon_processor(info_arch, options.cpu)
     if options.arch is None:
@@ -3115,8 +3100,6 @@ def canonicalize_options(options, info_os, info_arch):
 # This method DOES NOT change options on behalf of the user but explains
 # why the given configuration does not work.
 def validate_options(options, info_os, info_cc, available_module_policies):
-    # pylint: disable=too-many-branches,too-many-statements
-
     if options.name_amalgamation != 'botan_all':
         if options.name_amalgamation == '':
             raise UserError('Amalgamation basename must be non-empty')
@@ -3291,8 +3274,6 @@ def check_compiler_arch(options, ccinfo, archinfo, source_paths):
     return cc_output
 
 def do_io_for_build(cc, arch, osinfo, using_mods, info_modules, build_paths, source_paths, template_vars, options):
-    # pylint: disable=too-many-locals,too-many-branches,too-many-statements,too-many-arguments
-
     try:
         robust_rmtree(build_paths.build_dir)
     except OSError as ex:
@@ -3441,8 +3422,6 @@ def main(argv):
     Main driver
     """
 
-    # pylint: disable=too-many-locals,too-many-statements
-
     options = process_command_line(argv[1:])
 
     setup_logging(options)
diff --git a/src/configs/pylint.rc b/src/configs/pylint.rc
index b2ea98b81..7b6012727 100644
--- a/src/configs/pylint.rc
+++ b/src/configs/pylint.rc
@@ -31,13 +31,25 @@ confidence=
 # no Warning level messages displayed, use"--disable=all --enable=classes
 # --disable=W"
 
-# * consider-using-f-string and consider-using-with could be fixed now
-#   that we support only Python3, but neither seems that important
-# * missing-docstring isn't considered important because these are scripts
-#   not libraries
-# * fixme is marking TODOs in the future
-# * no-else-return is often awkward
-disable=missing-docstring,fixme,duplicate-code,no-else-return,consider-using-f-string,consider-using-with,broad-exception-raised
+disable=
+  # too-many-* is just like, your opinion man
+  too-many-lines,
+  too-many-locals,
+  too-many-statements,
+  too-many-branches,
+  too-many-arguments,
+  too-many-instance-attributes,
+  too-many-public-methods,
+
+  missing-docstring,       # nice to have, but not necessary in every script
+  fixme,                   # is it better to omit the note that something is worth improving???
+  duplicate-code,          # this triggers incorrectly all the time
+  no-else-return,          # often leads to awkward code
+  broad-exception-raised,  # this is fine to do in simple scripts
+  broad-except,            # there should be a catch-all handler
+  line-too-long,           # sometimes needed eg for test data
+  consider-using-f-string, # could fix this if we wanted, now that we are Python3 only
+  consider-using-with,     # could fix this if we wanted, now that we are Python3 only
 
 [REPORTS]
 
diff --git a/src/python/botan3.py b/src/python/botan3.py
index 2be49bb87..a5e836849 100755
--- a/src/python/botan3.py
+++ b/src/python/botan3.py
@@ -96,7 +96,6 @@ def _errcheck(rc, fn, _args):
     raise BotanException('%s failed' % (fn.__name__), rc)
 
 def _set_prototypes(dll):
-    # pylint: disable=too-many-statements,line-too-long
     def ffi_api(fn, args, allowed_errors=None):
         if allowed_errors is None:
             allowed_errors = [-10]
@@ -1567,7 +1566,6 @@ class X509Cert: # pylint: disable=invalid-name
                hostname=None,
                reference_time=0,
                crls=None):
-        #pylint: disable=too-many-locals
 
         if intermediates is not None:
             c_intermediates = len(intermediates) * c_void_p
@@ -1639,7 +1637,7 @@ class X509CRL:
         return self.__obj
 
 
-class MPI: # pylint: disable=too-many-public-methods
+class MPI:
 
     def __init__(self, initial_value=None, radix=None):
 
diff --git a/src/scripts/build_docs.py b/src/scripts/build_docs.py
index 554247674..951bbe4aa 100755
--- a/src/scripts/build_docs.py
+++ b/src/scripts/build_docs.py
@@ -135,7 +135,6 @@ def read_config(config):
     return cfg
 
 def main(args=None):
-    # pylint: disable=too-many-branches
 
     if args is None:
         args = sys.argv
diff --git a/src/scripts/ci_build.py b/src/scripts/ci_build.py
index 1c6ea79c6..9a545b433 100755
--- a/src/scripts/ci_build.py
+++ b/src/scripts/ci_build.py
@@ -86,7 +86,6 @@ def build_targets(target, target_os):
 def determine_flags(target, target_os, target_cpu, target_cc, cc_bin, ccache,
                     root_dir, build_dir, test_results_dir, pkcs11_lib, use_gdb,
                     disable_werror, extra_cxxflags, disabled_tests):
-    # pylint: disable=too-many-branches,too-many-statements,too-many-arguments,too-many-locals
 
     """
     Return the configure.py flags as well as make/test running prefixes
@@ -520,7 +519,6 @@ def have_prog(prog):
     return False
 
 def main(args=None):
-    # pylint: disable=too-many-branches,too-many-statements,too-many-locals,too-many-return-statements,too-many-locals
     """
     Parse options, do the things
     """
diff --git a/src/scripts/cleanup.py b/src/scripts/cleanup.py
index ae8e54c05..d020576a4 100755
--- a/src/scripts/cleanup.py
+++ b/src/scripts/cleanup.py
@@ -25,7 +25,7 @@ def remove_dir(d):
             shutil.rmtree(d)
         else:
             logging.debug('Directory %s was missing', d)
-    except Exception as e: # pylint: disable=broad-except
+    except Exception as e:
         logging.error('Failed removing directory "%s": %s', d, e)
 
 def remove_file(f):
@@ -90,7 +90,7 @@ def main(args=None):
         build_config_file = open(build_config_path, encoding='utf8')
         build_config_str = build_config_file.read()
         build_config_file.close()
-    except Exception: # pylint: disable=broad-except
+    except Exception:
         # Ugh have to do generic catch as different exception type thrown in Python2
         logging.error("Unable to access build_config.json in build dir")
         return 1
diff --git a/src/scripts/dev_tools/run_clang_format.py b/src/scripts/dev_tools/run_clang_format.py
index 5084887d5..1ff7e0dd0 100755
--- a/src/scripts/dev_tools/run_clang_format.py
+++ b/src/scripts/dev_tools/run_clang_format.py
@@ -89,7 +89,7 @@ def filter_files(files, filters):
 
     return files_to_fmt
 
-def main(args = None): # pylint: disable=too-many-locals
+def main(args = None):
     if args is None:
         args = sys.argv
 
diff --git a/src/scripts/dist.py b/src/scripts/dist.py
index 8e585c070..63d5dc56f 100755
--- a/src/scripts/dist.py
+++ b/src/scripts/dist.py
@@ -225,7 +225,6 @@ def rewrite_version_file(version_file, target_version, snapshot_branch, rev_id,
     open(version_file, 'w', encoding='utf8').write(new_contents)
 
 def write_archive(version, output_basename, archive_type, rel_epoch, all_files, hash_file):
-    # pylint: disable=too-many-locals
     def archive_suffix(archive_type):
         if archive_type == 'tgz':
             return 'tgz'
@@ -321,7 +320,6 @@ def configure_logging(options):
     logging.getLogger().setLevel(log_level())
 
 def main(args=None):
-    # pylint: disable=too-many-branches,too-many-locals,too-many-statements
     if args is None:
         args = sys.argv[1:]
 
@@ -461,7 +459,7 @@ def main(args=None):
 if __name__ == '__main__':
     try:
         sys.exit(main())
-    except Exception as e: # pylint: disable=broad-except
+    except Exception as e:
         logging.info(traceback.format_exc())
         logging.error(e)
         sys.exit(1)
diff --git a/src/scripts/install.py b/src/scripts/install.py
index 2d059bf5d..f4aee90b8 100755
--- a/src/scripts/install.py
+++ b/src/scripts/install.py
@@ -113,8 +113,6 @@ def calculate_exec_mode(options):
     return out
 
 def main(args):
-    # pylint: disable=too-many-locals,too-many-branches,too-many-statements
-
     logging.basicConfig(stream=sys.stdout,
                         format='%(levelname) 7s: %(message)s')
 
@@ -246,7 +244,7 @@ def main(args):
 if __name__ == '__main__':
     try:
         sys.exit(main(sys.argv))
-    except Exception as e: # pylint: disable=broad-except
+    except Exception as e:
         logging.error('Failure: %s', str(e))
         logging.info(traceback.format_exc())
         sys.exit(1)


Test patch:
diff --git a/src/scripts/test_cli.py b/src/scripts/test_cli.py
index cbc4fb2e6..b69ffe53d 100755
--- a/src/scripts/test_cli.py
+++ b/src/scripts/test_cli.py
@@ -72,7 +72,6 @@ def test_cli(cmd, cmd_options,
              expected_stderr=None,
              use_drbg=True,
              extra_env=None):
-    # pylint: disable=too-many-locals
     global TESTS_RUN
 
     TESTS_RUN += 1
@@ -549,7 +548,6 @@ def cli_rng_tests(_tmp_dir):
             logging.error('Unexpected RNG output %s', output)
 
 def cli_roughtime_check_tests(tmp_dir):
-    # pylint: disable=line-too-long
     if not check_for_command("roughtime_check"):
         return
     chain = os.path.join(tmp_dir, 'roughtime-chain')
@@ -579,8 +577,6 @@ ed25519 cj8GsiNlRkqiDElAeNMSBBMwrAl15hYPgX50+GWX/lA= Tsy82BBU2xxVqNe1ip11OyEGoKW
     test_cli("roughtime_check", chain, expected_stderr='Error: Roughtime: Invalid signature or public key')
 
 def cli_roughtime_tests(tmp_dir):
-    # pylint: disable=line-too-long
-    # pylint: disable=too-many-locals
     if not check_for_command("roughtime"):
         return
 
@@ -753,7 +749,6 @@ def cli_dl_group_info_tests(_tmp_dir):
 
 def cli_ec_group_info_tests(_tmp_dir):
 
-    # pylint: disable=line-too-long
     secp256r1_info = """P = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF
 A = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC
 B = 0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B
@@ -890,7 +885,6 @@ MCACAQUTBnN0cmluZzEGAQH/AgFjBAUAAAAAAAMEAP///w==
     test_cli("oid_info", "1.2.3.4", "OID 1.2.3.4 is not recognized")
 
 def cli_tls_socket_tests(tmp_dir):
-    # pylint: disable=too-many-locals,too-many-statements
     if not run_socket_tests() or not check_for_command("tls_client") or not check_for_command("tls_server"):
         return
 
@@ -1009,7 +1003,6 @@ def cli_tls_socket_tests(tmp_dir):
         logging.error("server said (stderr): %s", srv_stderr)
 
 def cli_tls_http_server_tests(tmp_dir):
-    # pylint: disable=too-many-locals
     if not run_socket_tests() or not check_for_command("tls_http_server"):
         return
 
@@ -1067,7 +1060,6 @@ def cli_tls_http_server_tests(tmp_dir):
         logging.error("Unexpected return code from https_server %d", rc)
 
 def cli_tls_proxy_tests(tmp_dir):
-    # pylint: disable=too-many-locals,too-many-statements
     if not run_socket_tests() or not check_for_command("tls_proxy"):
         return
 
@@ -1244,7 +1236,6 @@ def cli_uuid_tests(_tmp_dir):
 
 def cli_tls_client_hello_tests(_tmp_dir):
 
-    # pylint: disable=line-too-long
     chello = "16030100cf010000cb03035b3cf2457b864d7bef2a4b1f84fc3ced2b68d9551f3455ffdd305af277a91bb200003a16b816b716ba16b9cca9cca8c02cc030c02bc02fc0adc0acc024c00ac028c014c023c009c027c013ccaa009f009ec09fc09e006b003900670033010000680000000e000c000009676d61696c2e636f6d000500050100000000000a001a0018001d0017001a0018001b0019001c01000101010201030104000b00020100000d00140012080508040806050106010401050306030403001600000017000000230000ff01000100"
 
     output = test_cli("tls_client_hello", ["--hex", "-"], None, chello)
@@ -1349,7 +1340,6 @@ def cli_speed_math_tests(_tmp_dir):
                 logging.error("Unexpected line %s", line)
 
 def cli_speed_tests(_tmp_dir):
-    # pylint: disable=too-many-branches
 
     msec = 1
 
@@ -1358,7 +1348,6 @@ def cli_speed_tests(_tmp_dir):
     if len(output) % 4 != 0:
         logging.error("Unexpected number of lines for AES-128 speed test")
 
-    # pylint: disable=line-too-long
     format_re = re.compile(r'^AES-128 .* buffer size [0-9]+ bytes: [0-9]+\.[0-9]+ MiB\/sec .*\([0-9]+\.[0-9]+ MiB in [0-9]+\.[0-9]+ ms\)')
     for line in output:
         if format_re.match(line) is None:
@@ -1366,7 +1355,6 @@ def cli_speed_tests(_tmp_dir):
 
     output = test_cli("speed", ["--msec=%d" % (msec), "ChaCha20", "SHA-256", "HMAC(SHA-256)"], None).split('\n')
 
-    # pylint: disable=line-too-long
     format_re = re.compile(r'^.* buffer size [0-9]+ bytes: [0-9]+\.[0-9]+ MiB\/sec .*\([0-9]+\.[0-9]+ MiB in [0-9]+\.[0-9]+ ms\)')
     for line in output:
         if format_re.match(line) is None:
@@ -1425,7 +1413,7 @@ def run_test(fn_name, fn):
     tmp_dir = tempfile.mkdtemp(prefix='botan_cli_')
     try:
         fn(tmp_dir)
-    except Exception as e: # pylint: disable=broad-except
+    except Exception as e:
         logging.info(traceback.format_exc())
         logging.error("Test %s threw exception: %s", fn_name, e)
 
@@ -1434,7 +1422,6 @@ def run_test(fn_name, fn):
     logging.info("Ran %s in %.02f sec", fn_name, end-start)
 
 def main(args=None):
-    # pylint: disable=too-many-branches,too-many-locals
     if args is None:
         args = sys.argv
 
diff --git a/src/scripts/test_fuzzers.py b/src/scripts/test_fuzzers.py
index 31aace6be..dd48a4552 100755
--- a/src/scripts/test_fuzzers.py
+++ b/src/scripts/test_fuzzers.py
@@ -46,10 +46,6 @@ def run_fuzzer_many_files(fuzzer_bin, corpus_files):
     return (fuzzer_proc.returncode, stdout.decode('ascii'), stderr.decode('ascii'))
 
 def main(args=None):
-    #pylint: disable=too-many-branches
-    #pylint: disable=too-many-statements
-    #pylint: disable=too-many-locals
-
     if args is None:
         args = sys.argv
 
diff --git a/src/scripts/test_python.py b/src/scripts/test_python.py
index d20c2cd24..22cbd8704 100644
--- a/src/scripts/test_python.py
+++ b/src/scripts/test_python.py
@@ -37,8 +37,6 @@ def test_data(relpath):
     return os.path.join(TEST_DATA_DIR, relpath)
 
 class BotanPythonTests(unittest.TestCase):
-    # pylint: disable=too-many-public-methods,too-many-locals
-
     def test_version(self):
         version_str = botan.version_string()
         self.assertTrue(version_str.startswith('Botan '))
@@ -279,7 +277,7 @@ ofvkP1EDmpx50fHLawIDAQAB
         rsapub = botan.PublicKey.load(rsa_pub_pem)
         self.assertEqual(rsapub.to_pem(), rsa_pub_pem)
 
-        n = 0xB5AD8818DCA1F256FF8FAB0888D0667D95DF2098B0D201A4C75590D3EBDFA159DD91C64AFDA082609EF885B2D1F4DC055C8FF9FA371C2F3398E0B612C603151131C81DB322C8D15E53EB56B4DF7325F05046889CB25021DE4282E16B9B28F5CBB2B8DDECE0F8E4E8A77F674F26AE92B7220920A1FBE43F51039A9C79D1F1CB6B # pylint: disable=line-too-long
+        n = 0xB5AD8818DCA1F256FF8FAB0888D0667D95DF2098B0D201A4C75590D3EBDFA159DD91C64AFDA082609EF885B2D1F4DC055C8FF9FA371C2F3398E0B612C603151131C81DB322C8D15E53EB56B4DF7325F05046889CB25021DE4282E16B9B28F5CBB2B8DDECE0F8E4E8A77F674F26AE92B7220920A1FBE43F51039A9C79D1F1CB6B
         e = 0x10001
 
         rsapub2 = botan.PublicKey.load_rsa(n, e)
@@ -325,7 +323,6 @@ ofvkP1EDmpx50fHLawIDAQAB
             self.assertEqual(str(e), "botan_pubkey_load_rsa failed: -1 (Invalid input): Invalid RSA public key parameters")
 
     def test_rsa(self):
-        # pylint: disable=too-many-locals
         rng = botan.RandomNumberGenerator()
         rsapriv = botan.PrivateKey.create('RSA', '1024', rng)
         self.assertEqual(rsapriv.algo_name(), 'RSA')
@@ -477,7 +474,6 @@ ofvkP1EDmpx50fHLawIDAQAB
         self.assertTrue(verifier.check_signature(signature))
 
     def test_ecdh(self):
-        # pylint: disable=too-many-locals
         a_rng = botan.RandomNumberGenerator('user')
         b_rng = botan.RandomNumberGenerator('user')
 
@@ -515,7 +511,6 @@ ofvkP1EDmpx50fHLawIDAQAB
             self.assertEqual(a_pem, new_a.to_pem())
 
     def test_certs(self):
-        # pylint: disable=too-many-statements
         cert = botan.X509Cert(filename=test_data("src/tests/data/x509/ecc/CSCA.CSCA.csca-germany.1.crt"))
         pubkey = cert.subject_public_key()
 
@@ -597,7 +592,6 @@ ofvkP1EDmpx50fHLawIDAQAB
 
 
     def test_mpi(self):
-        # pylint: disable=too-many-statements,too-many-locals
         z = botan.MPI()
         self.assertEqual(z.bit_count(), 0)
         five = botan.MPI('5')