From 54f544581a2c213699a9e9930a70e29b8b401eea Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 27 May 2019 18:31:59 +0200 Subject: [PATCH] Pacify Pylint Pass Pylint by cleaning up the code where possible and silencing Pylint where I know better. No behavior change. --- scripts/generate_psa_constants.py | 6 ++---- tests/scripts/test_psa_constant_names.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/generate_psa_constants.py b/scripts/generate_psa_constants.py index d772a77fe..9def42a86 100755 --- a/scripts/generate_psa_constants.py +++ b/scripts/generate_psa_constants.py @@ -8,7 +8,6 @@ of that program. import os import re -import sys OUTPUT_TEMPLATE = '''\ /* Automatically generated by generate_psa_constant.py. DO NOT EDIT. */ @@ -224,12 +223,11 @@ class MacroCollector: return elif (name.startswith('PSA_ERROR_') or name == 'PSA_SUCCESS') \ and not parameter: - if name in [ - 'PSA_ERROR_UNKNOWN_ERROR', + if name in ['PSA_ERROR_UNKNOWN_ERROR', 'PSA_ERROR_OCCUPIED_SLOT', 'PSA_ERROR_EMPTY_SLOT', 'PSA_ERROR_INSUFFICIENT_CAPACITY', - ]: + ]: # Ad hoc skipping of deprecated error codes, which share # numerical values with non-deprecated error codes return diff --git a/tests/scripts/test_psa_constant_names.py b/tests/scripts/test_psa_constant_names.py index 43056bca3..1f08721a7 100755 --- a/tests/scripts/test_psa_constant_names.py +++ b/tests/scripts/test_psa_constant_names.py @@ -23,6 +23,8 @@ class ReadFileLineException(Exception): self.line_number = line_number class read_file_lines: + # Dear Pylint, conventionally, a context manager class name is lowercase. + # pylint: disable=invalid-name,too-few-public-methods '''Context manager to read a text file line by line. with read_file_lines(filename) as lines: for line in lines: @@ -36,6 +38,7 @@ snippet annotates the exception with the file name and line number.''' def __init__(self, filename): self.filename = filename self.line_number = 'entry' + self.generator = None def __enter__(self): self.generator = enumerate(open(self.filename, 'r')) return self @@ -119,6 +122,9 @@ where each argument takes each possible value at least once.''' argument_lists = [self.arguments_for[arg] for arg in argspec] arguments = [values[0] for values in argument_lists] yield self._format_arguments(name, arguments) + # Dear Pylint, enumerate won't work here since we're modifying + # the array. + # pylint: disable=consider-using-enumerate for i in range(len(arguments)): for value in argument_lists[i][1:]: arguments[i] = value @@ -224,7 +230,7 @@ def remove_file_if_exists(filename): return try: os.remove(filename) - except: + except OSError: pass def run_c(options, type_word, names): @@ -318,7 +324,7 @@ not as expected.''' errors += e return count, errors -if __name__ == '__main__': +def main(): parser = argparse.ArgumentParser(description=globals()['__doc__']) parser.add_argument('--include', '-I', action='append', default=['include'], @@ -344,3 +350,6 @@ if __name__ == '__main__': else: print('{} test cases, {} FAIL'.format(count, len(errors))) exit(1) + +if __name__ == '__main__': + main()