From 8be589f051229c51f1b94941a22211d6e942d62d Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 16 Sep 2024 14:31:17 +0200 Subject: [PATCH 1/2] enabled and fixed `use-list-literal` pylint warnings --- .pylintrc | 1 - addons/cppcheckdata.py | 6 +++--- addons/misra.py | 14 +++++++------- tools/compare-normal-exhaustive.py | 2 +- tools/test-my-pr.py | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.pylintrc b/.pylintrc index b00b486e4a8..ea360676d8a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -52,7 +52,6 @@ disable= consider-using-with, too-many-statements, too-many-branches, - use-list-literal, simplifiable-if-statement, too-many-locals, too-many-arguments, diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index a7fa1bd74b3..aedad755b7d 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -588,14 +588,14 @@ def __init__(self, element): self.bodyEnd = None self.nestedInId = element.get('nestedIn') self.nestedIn = None - self.nestedList = list() + self.nestedList = [] self.type = element.get('type') self.definedType = element.get('definedType') self.isExecutable = (self.type in ('Function', 'If', 'Else', 'For', 'While', 'Do', 'Switch', 'Try', 'Catch', 'Unconditional', 'Lambda')) - self.varlistId = list() - self.varlist = list() + self.varlistId = [] + self.varlist = [] def __repr__(self): attrs = ["Id", "className", "functionId", "bodyStartId", "bodyEndId", diff --git a/addons/misra.py b/addons/misra.py index 083392807be..45fb544e690 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1367,8 +1367,8 @@ def __init__(self, settings, stdversion="c89"): self.settings = settings # Test validation rules lists - self.verify_expected = list() - self.verify_actual = list() + self.verify_expected = [] + self.verify_actual = [] # List of formatted violation messages self.violations = dict() @@ -1588,7 +1588,7 @@ def misra_2_4(self, dumpfile, cfg): self._save_ctu_summary_tagnames(dumpfile, cfg) def misra_2_5(self, dumpfile, cfg): - used_macros = list() + used_macros = [] for m in cfg.macro_usage: used_macros.append(m.name) summary = [] @@ -1606,7 +1606,7 @@ def misra_2_7(self, data): if len(func.argument) == 0: continue # Setup list of function parameters - func_param_list = list() + func_param_list = [] for arg in func.argument: func_arg = func.argument[arg] if func_arg.typeStartToken and func_arg.typeStartToken.str == '...': @@ -4124,7 +4124,7 @@ def addSuppressedRule(self, ruleNum, # If the rule is not in the dict already then add it if ruleNum not in self.suppressedRules: - ruleItemList = list() + ruleItemList = [] ruleItemList.append(line_symbol) fileDict = dict() @@ -4143,7 +4143,7 @@ def addSuppressedRule(self, ruleNum, # If the filename is not in the dict already add it if normalized_filename not in fileDict: - ruleItemList = list() + ruleItemList = [] ruleItemList.append(line_symbol) fileDict[normalized_filename] = ruleItemList @@ -4247,7 +4247,7 @@ def showSuppressedRules(self): Print out rules in suppression list sorted by Rule Number """ print("Suppressed Rules List:") - outlist = list() + outlist = [] for ruleNum in self.suppressedRules: fileDict = self.suppressedRules[ruleNum] diff --git a/tools/compare-normal-exhaustive.py b/tools/compare-normal-exhaustive.py index 6eca7f12038..6f4cf5a2afa 100755 --- a/tools/compare-normal-exhaustive.py +++ b/tools/compare-normal-exhaustive.py @@ -117,7 +117,7 @@ def format_float(a, b=1): print("No files to process") continue - results_to_diff = list() + results_to_diff = [] normal_crashed = False exhaustive_crashed = False diff --git a/tools/test-my-pr.py b/tools/test-my-pr.py index 2f33a824423..de897c09bd6 100755 --- a/tools/test-my-pr.py +++ b/tools/test-my-pr.py @@ -144,7 +144,7 @@ def format_float(a, b=1): print("No files to process") continue - results_to_diff = list() + results_to_diff = [] main_crashed = False your_crashed = False From 221bae0ddd872130502f0e350a32cb57b99bd297 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 16 Sep 2024 14:32:26 +0200 Subject: [PATCH 2/2] enabled and fixed `use-dict-literal` pylint warnings --- .pylintrc | 1 - addons/misra.py | 10 +++++----- htmlreport/cppcheck-htmlreport | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.pylintrc b/.pylintrc index ea360676d8a..52bb1e43641 100644 --- a/.pylintrc +++ b/.pylintrc @@ -64,7 +64,6 @@ disable= too-many-nested-blocks, too-many-public-methods, consider-using-sys-exit, - use-dict-literal, chained-comparison, too-many-instance-attributes, consider-using-join, diff --git a/addons/misra.py b/addons/misra.py index 45fb544e690..8ab57985f98 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1371,13 +1371,13 @@ def __init__(self, settings, stdversion="c89"): self.verify_actual = [] # List of formatted violation messages - self.violations = dict() + self.violations = {} # if --rule-texts is specified this dictionary # is loaded with descriptions of each rule # by rule number (in hundreds). # ie rule 1.2 becomes 102 - self.ruleTexts = dict() + self.ruleTexts = {} self.ruleText_filename = None # Dictionary of dictionaries for rules to suppress @@ -1388,13 +1388,13 @@ def __init__(self, settings, stdversion="c89"): # or an item of None which indicates suppress rule for the entire file. # The line and symbol name tuple may have None as either of its elements but # should not be None for both. - self.suppressedRules = dict() + self.suppressedRules = {} # Prefix to ignore when matching suppression files. self.filePrefix = None # Number of all violations suppressed per rule - self.suppressionStats = dict() + self.suppressionStats = {} self.stdversion = stdversion @@ -4127,7 +4127,7 @@ def addSuppressedRule(self, ruleNum, ruleItemList = [] ruleItemList.append(line_symbol) - fileDict = dict() + fileDict = {} fileDict[normalized_filename] = ruleItemList self.suppressedRules[ruleNum] = fileDict diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index 9196431f781..95c9bf3ff2b 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -447,7 +447,7 @@ def git_blame(errors, path, file, blame_options): blame_data = [] line_from = 0 line_to = 0 - blame_info = dict() + blame_info = {} for line_str in result.splitlines(): field, _, value = line_str.partition(' ')