From d91eb516f207b9d8704c60f78bc3c642fb1940d0 Mon Sep 17 00:00:00 2001
From: Allan Blanchard <allan.blanchard@cea.fr>
Date: Wed, 19 Jul 2023 16:03:28 +0200
Subject: [PATCH] [tests] python scripts to black 23

---
 share/analysis-scripts/build.py                    | 2 +-
 share/analysis-scripts/build_callgraph.py          | 8 ++++----
 share/analysis-scripts/estimate_difficulty.py      | 4 ++--
 share/analysis-scripts/frama_c_results.py          | 2 +-
 share/analysis-scripts/function_finder.py          | 5 ++++-
 share/analysis-scripts/heuristic_list_functions.py | 2 +-
 share/analysis-scripts/list_files.py               | 3 ++-
 tests/compliance/sanity-checks.py                  | 4 ++--
 8 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/share/analysis-scripts/build.py b/share/analysis-scripts/build.py
index 33c5ea5268b..a373e31c752 100755
--- a/share/analysis-scripts/build.py
+++ b/share/analysis-scripts/build.py
@@ -366,7 +366,7 @@ for target, sources in sources_map.items():
             main,
             prettify(target),
         )
-        for (filename, line, _) in main_definitions[target]:
+        for filename, line, _ in main_definitions[target]:
             print(f"- definition at {filename}:{line}")
 
 # End of checks; start writing GNUmakefile and stubs from templates ###########
diff --git a/share/analysis-scripts/build_callgraph.py b/share/analysis-scripts/build_callgraph.py
index 1e19584263f..d0b796e20dd 100755
--- a/share/analysis-scripts/build_callgraph.py
+++ b/share/analysis-scripts/build_callgraph.py
@@ -93,7 +93,7 @@ def compute(files):
 
 def print_edge(cg: Callgraph, caller, called, padding="", end="\n") -> None:
     locs = cg.edges[(caller, called)]
-    for (filename, line) in locs:
+    for filename, line in locs:
         print(
             f"{padding}{os.path.relpath(filename)}:{line}: {caller} -> {called}",
             end=end,
@@ -101,14 +101,14 @@ def print_edge(cg: Callgraph, caller, called, padding="", end="\n") -> None:
 
 
 def print_cg(cg: Callgraph) -> None:
-    for (caller, called) in cg.edges:
+    for caller, called in cg.edges:
         print_edge(cg, caller, called)
 
 
 # note: out _must_ exist (the caller must create it if needed)
 def print_cg_dot(cg: Callgraph, out=sys.stdout) -> None:
     print("digraph callgraph {", file=out)
-    for (caller, called) in cg.edges:
+    for caller, called in cg.edges:
         print(f"  {caller} -> {called};", file=out)
     print("}", file=out)
 
@@ -177,7 +177,7 @@ def detect_recursion(cg) -> None:
         if cycle:
             has_cycle = True
             print("recursive cycle detected: ")
-            for (caller, called) in cycle:
+            for caller, called in cycle:
                 print_edge(cg, caller, called, padding="  ")
         to_visit -= visited
     if not has_cycle:
diff --git a/share/analysis-scripts/estimate_difficulty.py b/share/analysis-scripts/estimate_difficulty.py
index 7e5af576871..a4fb891a9f0 100755
--- a/share/analysis-scripts/estimate_difficulty.py
+++ b/share/analysis-scripts/estimate_difficulty.py
@@ -176,7 +176,7 @@ with open(framac_share / "compliance" / "posix_identifiers.json", encoding="utf-
 recursive_cycles: list[tuple[tuple[str, int], list[tuple[str, str]]]] = []
 reported_recursive_pairs = set()
 build_callgraph.compute_recursive_cycles(cg, recursive_cycles)
-for (cycle_start_loc, cycle) in recursive_cycles:
+for cycle_start_loc, cycle in recursive_cycles:
     # Note: in larger code bases, many cycles are reported for the same final
     # function (e.g. for the calls 'g -> g', we may have 'f -> g -> g',
     # 'h -> g -> g', etc; to minimize this, we print just the first one.
@@ -188,7 +188,7 @@ for (cycle_start_loc, cycle) in recursive_cycles:
     (filename, line) = cycle_start_loc
     (x, y) = cycle[0]
     pretty_cycle = f"{x} -> {y}"
-    for (x, y) in cycle[1:]:
+    for x, y in cycle[1:]:
         pretty_cycle += f" -> {y}"
     print(f"[recursion] found recursive cycle near {filename}:{line}: {pretty_cycle}")
 
diff --git a/share/analysis-scripts/frama_c_results.py b/share/analysis-scripts/frama_c_results.py
index 241a1cbd361..e5d807b9805 100644
--- a/share/analysis-scripts/frama_c_results.py
+++ b/share/analysis-scripts/frama_c_results.py
@@ -30,7 +30,7 @@ def load(filename):
     try:
         with open(filename, "r") as file:
             content = file.read()
-            for (key, value) in stat_file_re.findall(content):
+            for key, value in stat_file_re.findall(content):
                 data[key] = value
     except OSError:
         pass
diff --git a/share/analysis-scripts/function_finder.py b/share/analysis-scripts/function_finder.py
index 2c50fe7a5e4..0ee97baef63 100644
--- a/share/analysis-scripts/function_finder.py
+++ b/share/analysis-scripts/function_finder.py
@@ -53,6 +53,7 @@ argument_list = r"\([^)]*\)"
 
 debug = os.getenv("DEBUG", False)
 
+
 # Precomputes the regex for 'fname'
 def prepare_re_specific_name(fname):
     re_fun = re.compile(
@@ -106,6 +107,7 @@ def compute_re_def_or_decl(funcname):
 # matches function calls
 re_funcall = re.compile("(" + c_identifier + ")" + whitespace + r"\(")
 
+
 # Computes the offset (in bytes) of each '\n' in the file,
 # returning them as a list
 def compute_newline_offsets(file_lines):
@@ -223,6 +225,7 @@ def find_definitions_and_declarations(
 # list of identifiers which are never function calls
 calls_blacklist = ["if", "while", "for", "return", "sizeof", "switch", "_Alignas"]
 
+
 # Returns a list of tuples (fname, line, offset) for each function call.
 #
 # Note: this may include the function prototype itself;
@@ -246,7 +249,7 @@ def find_calls(file_content, newlines):
 # [defs] must be sorted in ascending order.
 def find_caller(defs, call):
     (_called, line, offset) = call
-    for (fname, _is_def, start, end, brace_offset) in defs:
+    for fname, _is_def, start, end, brace_offset in defs:
         if start <= line <= end and offset > brace_offset:
             return fname
         elif start > line:
diff --git a/share/analysis-scripts/heuristic_list_functions.py b/share/analysis-scripts/heuristic_list_functions.py
index f3ce02728c6..2778f5b2111 100755
--- a/share/analysis-scripts/heuristic_list_functions.py
+++ b/share/analysis-scripts/heuristic_list_functions.py
@@ -59,7 +59,7 @@ for f in files:
     defs_and_decls = function_finder.find_definitions_and_declarations(
         want_defs, want_decls, f, file_content, file_lines, newlines
     )
-    for (funcname, is_def, start, end, _offset) in defs_and_decls:
+    for funcname, is_def, start, end, _offset in defs_and_decls:
         if is_def:
             print(f"{os.path.relpath(f)}:{start}:{end}: {funcname} (definition)")
         else:
diff --git a/share/analysis-scripts/list_files.py b/share/analysis-scripts/list_files.py
index 14cf8de0951..37e5a8bc7ff 100755
--- a/share/analysis-scripts/list_files.py
+++ b/share/analysis-scripts/list_files.py
@@ -42,6 +42,7 @@ else:
 if not arg.exists():
     sys.exit(f"error: file '{arg}' not found")
 
+
 # check if arg has a known extension
 def is_known_c_extension(ext):
     return ext in (".c", ".i", ".ci", ".h")
@@ -79,7 +80,7 @@ print("")
 
 files_defining_main = set()
 re_main = re.compile(r"(int|void)\s+main\s*\([^)]*\)\s*\{")
-for (fname, file_for_fcmake) in files:
+for fname, file_for_fcmake in files:
     assert os.path.exists(fname), "file does not exist: %s" % fname
     with open(fname, "r") as content_file:
         content = content_file.read()
diff --git a/tests/compliance/sanity-checks.py b/tests/compliance/sanity-checks.py
index 6bc3186325f..b081be92ef9 100755
--- a/tests/compliance/sanity-checks.py
+++ b/tests/compliance/sanity-checks.py
@@ -22,7 +22,7 @@ with open(posix_ids_path) as data:
     posix_headers = set(js["headers"].keys())
     extension_names = set(js["extension_names"].keys())
     unique_ids = set()
-    for (i, v) in posix_dict.items():
+    for i, v in posix_dict.items():
         if i in unique_ids:
             sys.exit("duplicate id {i}")
         unique_ids.add(i)
@@ -50,7 +50,7 @@ with open(c11_funs_path) as data:
     js = json.load(data)
     c11_funs = js["data"]
 
-for (i, v) in c11_funs.items():
+for i, v in c11_funs.items():
     header = v["header"]
     if header not in c11_headers:
         sys.exit(f"error: unknown header {header} for id {i}")
-- 
GitLab