Several Python scripts contain C-style semicolons, unused imports,
equality comparisons with None, and regular expressions with invalid
escape sequences.  Newer Python versions warn about the latter.

Remove the semicolons and unused imports, use raw strings for regular
expressions, and compare None by identity.  No functional change is
intended.

contrib/ChangeLog:

        * analyze_brprob.py: Use identity comparisons with None and a raw
        string for a regular expression.
        * check_GNU_style_lib.py: Use identity comparisons with None.
        * regenerate-sarif-spec-index.py: Remove a semicolon.
        * testsuite-management/validate_failures.py: Use identity
        comparisons with None.
        * unicode/gen_libstdcxx_unicode_data.py: Remove semicolons.
        * unused_functions.py: Likewise.

contrib/header-tools/ChangeLog:

        * headerutils.py: Remove unused imports and semicolons.  Use raw
        strings for regular expressions and identity comparisons with None.

gcc/testsuite/ChangeLog:

        * libgdiagnostics.dg/test-warning-with-path-c.py: Remove semicolons.

Signed-off-by: Oleg Tolmatcev <[email protected]>
---
 contrib/analyze_brprob.py                     | 18 +++++------
 contrib/check_GNU_style_lib.py                | 22 ++++++-------
 contrib/header-tools/headerutils.py           | 32 +++++++++----------
 contrib/regenerate-sarif-spec-index.py        |  2 +-
 .../testsuite-management/validate_failures.py |  4 +--
 contrib/unicode/gen_libstdcxx_unicode_data.py | 10 +++---
 contrib/unused_functions.py                   |  2 +-
 .../test-warning-with-path-c.py               |  6 ++--
 8 files changed, 47 insertions(+), 49 deletions(-)

I don't have write access BTW.

diff --git a/contrib/analyze_brprob.py b/contrib/analyze_brprob.py
index 3495f59abb..9698b2c69a 100755
--- a/contrib/analyze_brprob.py
+++ b/contrib/analyze_brprob.py
@@ -113,16 +113,16 @@ class PredictDefFile:
             elif l == '':
                 p = None
 
-            if p != None:
+            if p is not None:
                 heuristic = [x for x in heuristics if x.name == p]
                 heuristic = heuristic[0] if len(heuristic) == 1 else None
 
-                m = re.match('.*HITRATE \(([^)]*)\).*', l)
-                if (m != None):
+                m = re.match(r'.*HITRATE \(([^)]*)\).*', l)
+                if (m is not None):
                     self.predictors[p] = int(m.group(1))
 
                     # modify the line
-                    if heuristic != None:
+                    if heuristic is not None:
                         new_line = (l[:m.start(1)]
                             + str(round(heuristic.get_hitrate()))
                             + l[m.end(1):])
@@ -183,14 +183,14 @@ class Summary:
     def print(self, branches_max, count_max, predict_def):
         # filter out most hot edges (if requested)
         self.edges = sorted(self.edges, reverse = True, key = lambda x: 
x.count)
-        if args.coverage_threshold != None:
+        if args.coverage_threshold is not None:
             threshold = args.coverage_threshold * self.count() / 100
             edges = [x for x in self.edges if x.count < threshold]
             if len(edges) != 0:
                 self.edges = edges
 
         predicted_as = None
-        if predict_def != None and self.name in predict_def.predictors:
+        if predict_def is not None and self.name in predict_def.predictors:
             predicted_as = predict_def.predictors[self.name]
 
         print('%-40s %8i %5.1f%% %11.2f%% %7.2f%% / %6.2f%% %14i %8s %5.1f%%' %
@@ -202,14 +202,14 @@ class Summary:
                 self.count(), self.count_formatted(),
                 percentage(self.count(), count_max)), end = '')
 
-        if predicted_as != None:
+        if predicted_as is not None:
             print('%12i%% %5.1f%%' % (predicted_as,
                 self.get_hitrate() - predicted_as), end = '')
         else:
             print(' ' * 20, end = '')
 
         # print details about the most important edges
-        if args.coverage_threshold == None:
+        if args.coverage_threshold is None:
             edges = [x for x in self.edges[:100] if x.count * hot_threshold > 
self.count()]
             if args.verbose:
                 for c in edges:
@@ -277,7 +277,7 @@ class Profile:
             return
 
         predict_def = None
-        if args.def_file != None:
+        if args.def_file is not None:
             predict_def = PredictDefFile(args.def_file)
             predict_def.parse_and_modify(heuristics, args.write_def_file)
 
diff --git a/contrib/check_GNU_style_lib.py b/contrib/check_GNU_style_lib.py
index d057faa51c..5a02533b7b 100755
--- a/contrib/check_GNU_style_lib.py
+++ b/contrib/check_GNU_style_lib.py
@@ -119,7 +119,7 @@ class TrailingWhitespaceCheck:
     def check(self, filename, lineno, line):
         assert(len(line) == 0 or line[-1] != '\n')
         m = self.re.search(line)
-        if m != None:
+        if m is not None:
             return CheckError(filename, lineno,
                 line[:m.start(1)] + error_string(ws_char * len(m.group(1)))
                 + line[m.end(1):],
@@ -131,7 +131,7 @@ class SentenceSeparatorCheck:
 
     def check(self, filename, lineno, line):
         m = self.re.search(line)
-        if m != None:
+        if m is not None:
             return CheckError(filename, lineno,
                 line[:m.start(1)] + error_string(ws_char * len(m.group(1)))
                 + line[m.end(1):],
@@ -143,7 +143,7 @@ class SentenceEndOfCommentCheck:
 
     def check(self, filename, lineno, line):
         m = self.re.search(line)
-        if m != None:
+        if m is not None:
             return CheckError(filename, lineno,
                 line[:m.start(1)] + error_string(ws_char * len(m.group(1)))
                 + line[m.end(1):],
@@ -155,7 +155,7 @@ class SentenceDotEndCheck:
 
     def check(self, filename, lineno, line):
         m = self.re.search(line)
-        if m != None:
+        if m is not None:
             return CheckError(filename, lineno,
                 line[:m.start(1)] + error_string(m.group(1)) + line[m.end(1):],
                 'dot, space, space, end of comment', m.start(1))
@@ -173,7 +173,7 @@ class FunctionParenthesisCheck:
             return None
 
         m = self.re.search(line)
-        if m != None:
+        if m is not None:
             return CheckError(filename, lineno,
                 line[:m.start(2)] + error_string(m.group(2)) + line[m.end(2):],
                 'there should be exactly one space between function name ' \
@@ -188,7 +188,7 @@ class SquareBracketCheck:
             return None
 
         m = self.re.search(line)
-        if m != None:
+        if m is not None:
             return CheckError(filename, lineno,
                 line[:m.start(1)] + error_string(m.group(1)) + line[m.end(1):],
                 'there should be no space before a left square bracket',
@@ -200,7 +200,7 @@ class ClosingParenthesisCheck:
 
     def check(self, filename, lineno, line):
         m = self.re.search(line)
-        if m != None:
+        if m is not None:
             return CheckError(filename, lineno,
                 line[:m.start(1)] + error_string(m.group(1)) + line[m.end(1):],
                 'there should be no space before closing parenthesis',
@@ -214,7 +214,7 @@ class BracesOnSeparateLineCheck:
 
     def check(self, filename, lineno, line):
         m = self.re.search(line)
-        if m != None:
+        if m is not None:
             return CheckError(filename, lineno,
                 line[:m.start(2)] + error_string(m.group(2)) + line[m.end(2):],
                 'braces should be on a separate line', m.start(2))
@@ -226,7 +226,7 @@ class TrailingOperatorCheck:
 
     def check(self, filename, lineno, line):
         m = self.re.search(line)
-        if m != None:
+        if m is not None:
             return CheckError(filename, lineno,
                 line[:m.start(1)] + error_string(m.group(1)) + line[m.end(1):],
                 'trailing operator', m.start(1))
@@ -294,11 +294,11 @@ def check_GNU_style_file(file, format):
         for hunk in pfile:
             delta = 0
             for line in hunk:
-                if line.is_added and line.target_line_no != None:
+                if line.is_added and line.target_line_no is not None:
                     for check in checks:
                         line_chomp = line.value.replace('\n', '')
                         e = check.check(t, line.target_line_no, line_chomp)
-                        if e != None:
+                        if e is not None:
                             errors.append(e)
 
     if format == 'stdio':
diff --git a/contrib/header-tools/headerutils.py 
b/contrib/header-tools/headerutils.py
index 1fb0221441..5a18dbb76a 100755
--- a/contrib/header-tools/headerutils.py
+++ b/contrib/header-tools/headerutils.py
@@ -1,10 +1,8 @@
 #! /usr/bin/python3
 import os.path
 import sys
-import shlex
 import re
 import subprocess
-import shutil
 import pickle
 
 import multiprocessing 
@@ -31,19 +29,19 @@ def find_pound_define (line):
       print ("What? more than 1 match in #define??")
       print (inc)
       sys.exit(5)
-    return inc[0];
+    return inc[0]
   return ""
 
 def is_pound_if (line):
-  inc = re.findall ("^\s*#\s*if\s", line)
+  inc = re.findall (r"^\s*#\s*if\s", line)
   if not inc:
-    inc = re.findall ("^\s*#\s*if[n]?def\s", line)
+    inc = re.findall (r"^\s*#\s*if[n]?def\s", line)
   if inc:
     return True
   return False
 
 def is_pound_endif (line):
-  inc = re.findall ("^\s*#\s*endif", line)
+  inc = re.findall (r"^\s*#\s*endif", line)
   if inc:
     return True
   return False
@@ -95,7 +93,7 @@ def process_include_info (filen, do_macros, keep_src):
   if not os.path.exists (filen):
     return empty_iinfo
 
-  sfile = open (filen, "r");
+  sfile = open (filen, "r")
   data = sfile.readlines()
   sfile.close()
 
@@ -132,7 +130,7 @@ def process_include_info (filen, do_macros, keep_src):
       d = find_pound_define (line)
       if d:
         if d not in macout:
-          macout.append (d);
+          macout.append (d)
           continue
 
       d = find_pound_if (line)
@@ -146,7 +144,7 @@ def process_include_info (filen, do_macros, keep_src):
         else:
           for mac in d:
             if mac != "defined" and mac not in macin:
-              macin.append (mac);
+              macin.append (mac)
 
   if not keep_src:
     data = list()
@@ -299,7 +297,7 @@ def find_unique_include_list (filen):
 # (filen, macin, macout, incl)
 
 def create_macro_in_out (filen):
-  sfile = open (filen, "r");
+  sfile = open (filen, "r")
   data = sfile.readlines()
   sfile.close()
 
@@ -311,14 +309,14 @@ def create_macro_in_out (filen):
     d = find_pound_define (line)
     if d != "":
       if d not in macout:
-        macout.append (d);
+        macout.append (d)
       continue
 
     d = find_pound_if (line)
     if len(d) != 0:
       for mac in d:
         if mac != "defined" and mac not in macin:
-          macin.append (mac);
+          macin.append (mac)
       continue
 
     nm = find_pound_include (line, True, True)
@@ -399,7 +397,7 @@ def find_replace_include (find, replace, src):
     inc = find_pound_include (line, True, True)
     if inc == find:
       for y in replace:
-        if seen.get(y) == None:
+        if seen.get(y) is None:
           res.append("#include \""+y+"\"\n")
           seen[y] = True
           if y != find:
@@ -409,7 +407,7 @@ def find_replace_include (find, replace, src):
         anything = True
     else:
       if inc in replace:
-        if seen.get(inc) == None:
+        if seen.get(inc) is None:
           res.append (line)
           seen[inc] = True
       else:
@@ -474,7 +472,7 @@ def get_make_rc (rc, output):
     h = re.findall ("warning: inline function.*used but never defined", output)
     if len(h) != 0:
       rc = 1
-  return rc;
+  return rc
 
 def get_make_output (build_dir, make_opt):
   devnull = open('/dev/null', 'w')
@@ -485,7 +483,7 @@ def get_make_output (build_dir, make_opt):
   else:
     command = make + make_opt
   process = subprocess.Popen(command, stdout=devnull, stderr=subprocess.PIPE, 
shell=True)
-  output = process.communicate();
+  output = process.communicate()
   rc = get_make_rc (process.returncode, output[1])
   return (rc , output[1])
 
@@ -509,7 +507,7 @@ def spawn_makes (command_list):
     if (ret[0] != 0):
       # Just record the first one.
       if rc[0] == 0:
-        rc = ret;
+        rc = ret
   return rc
 
 def get_make_output_parallel (targ_list, make_opt, at_a_time):
diff --git a/contrib/regenerate-sarif-spec-index.py 
b/contrib/regenerate-sarif-spec-index.py
index 9f675e311f..cac0b6e3b8 100644
--- a/contrib/regenerate-sarif-spec-index.py
+++ b/contrib/regenerate-sarif-spec-index.py
@@ -54,7 +54,7 @@ with open(filename_out, 'w') as outfile:
                   '{\n'
                   '  const char *m_ref;\n'
                   '  const char *m_anchor;\n'
-                  '} sarif_spec_anchor_arr[] = {\n');
+                  '} sarif_spec_anchor_arr[] = {\n')
     for ref, anchor in d.items():
         outfile.write(f'  {{ "{ref}", "{anchor}" }},\n')
     outfile.write('};')
diff --git a/contrib/testsuite-management/validate_failures.py 
b/contrib/testsuite-management/validate_failures.py
index ce8a613ee8..7439b2757a 100755
--- a/contrib/testsuite-management/validate_failures.py
+++ b/contrib/testsuite-management/validate_failures.py
@@ -143,7 +143,7 @@ class TestResult(object):
               file=sys.stderr)
         raise
       self.ordinal = ordinal
-      if tool == None or exp == None:
+      if tool is None or exp is None:
         # .sum file seem to be broken.  There was no "tool" and/or "exp"
         # lines preceding this result.
         print(f'.sum file seems to be broken: tool="{tool}", exp="{exp}", 
summary_line="{summary_line}"',
@@ -458,7 +458,7 @@ def CollectSumFiles(builddir):
 
 def GetResults(sum_files, build_results = None):
   """Collect all the test results from the given .sum files."""
-  if build_results == None:
+  if build_results is None:
     build_results = ResultSet()
   for sum_fname in sum_files:
     if _OPTIONS.verbosity >= 3:
diff --git a/contrib/unicode/gen_libstdcxx_unicode_data.py 
b/contrib/unicode/gen_libstdcxx_unicode_data.py
index 91cb201e1f..d5aac5b6cb 100755
--- a/contrib/unicode/gen_libstdcxx_unicode_data.py
+++ b/contrib/unicode/gen_libstdcxx_unicode_data.py
@@ -128,7 +128,7 @@ edges = find_edges(all_code_points, 1)
 # Table for std::__unicode::__format_width(char32_t)
 
 print("  // Table generated by contrib/unicode/gen_libstdcxx_unicode_data.py,")
-print("  // from EastAsianWidth.txt from the Unicode standard.");
+print("  // from EastAsianWidth.txt from the Unicode standard.")
 print("  inline constexpr char32_t __width_edges[] = {", end="")
 for i, e in enumerate(edges):
     if i % 8:
@@ -165,7 +165,7 @@ edges = find_edges(all_code_points)
 
 shift_bits = 1
 print("  // Values generated by 
contrib/unicode/gen_libstdcxx_unicode_data.py,")
-print("  // from DerivedGeneralCategory.txt from the Unicode standard.");
+print("  // from DerivedGeneralCategory.txt from the Unicode standard.")
 print("  // Entries are (code_point << 1) + escape.")
 print("  inline constexpr uint32_t __escape_edges[] = {", end="")
 for i, e in enumerate(edges):
@@ -208,7 +208,7 @@ print("  };\n")
 # Tables for std::__unicode::_Grapheme_cluster_state
 
 print("  // Values generated by 
contrib/unicode/gen_libstdcxx_unicode_data.py,")
-print("  // from GraphemeBreakProperty.txt from the Unicode standard.");
+print("  // from GraphemeBreakProperty.txt from the Unicode standard.")
 print("  // Entries are (code_point << shift_bits) + property.")
 print("  inline constexpr int __gcb_shift_bits = {:#x};".format(shift_bits))
 print("  inline constexpr uint32_t __gcb_edges[] = {", end="")
@@ -250,7 +250,7 @@ incb_props = {None:0, "Consonant":1, "Extend":2}
 print("  enum class _InCB { _Consonant = 1, _Extend = 2 };\n")
 # Table for std::__unicode::__incb_property
 print("  // Values generated by 
contrib/unicode/gen_libstdcxx_unicode_data.py,")
-print("  // from DerivedCoreProperties.txt from the Unicode standard.");
+print("  // from DerivedCoreProperties.txt from the Unicode standard.")
 print("  // Entries are (code_point << 2) + property.")
 print("  inline constexpr uint32_t __incb_edges[] = {", end="")
 for i, e in enumerate(edges):
@@ -279,7 +279,7 @@ edges = find_edges(all_code_points, False)
 
 # Table for std::__unicode::__is_extended_pictographic
 print("  // Table generated by contrib/unicode/gen_libstdcxx_unicode_data.py,")
-print("  // from emoji-data.txt from the Unicode standard.");
+print("  // from emoji-data.txt from the Unicode standard.")
 print("  inline constexpr char32_t __xpicto_edges[] = {", end="")
 for i, e in enumerate(edges):
     if i % 8:
diff --git a/contrib/unused_functions.py b/contrib/unused_functions.py
index dd6e5dd6b9..81f71da8c6 100755
--- a/contrib/unused_functions.py
+++ b/contrib/unused_functions.py
@@ -24,7 +24,7 @@ from subprocess import Popen, PIPE
 def usage():
     sys.stderr.write("usage: %s [-v] [dirs | files] [-- <readelf options>]\n"
                         % sys.argv[0])
-    sys.stderr.write("\t-v\tVerbose output\n");
+    sys.stderr.write("\t-v\tVerbose output\n")
     sys.exit(1)
 
 (odir, sym_args, tmpd, verbose) = (set(), "", None, False)
diff --git a/gcc/testsuite/libgdiagnostics.dg/test-warning-with-path-c.py 
b/gcc/testsuite/libgdiagnostics.dg/test-warning-with-path-c.py
index 61ccb93336..e905a41ff2 100644
--- a/gcc/testsuite/libgdiagnostics.dg/test-warning-with-path-c.py
+++ b/gcc/testsuite/libgdiagnostics.dg/test-warning-with-path-c.py
@@ -8,9 +8,9 @@ def sarif():
 
 final_line_num = 34
 
-line_num_call_to_PyList_New = final_line_num - 7;
-line_num_for_loop = final_line_num - 5;
-line_num_call_to_PyList_Append = final_line_num - 3;
+line_num_call_to_PyList_New = final_line_num - 7
+line_num_for_loop = final_line_num - 5
+line_num_call_to_PyList_Append = final_line_num - 3
 
 expected_file_name = 'test-warning-with-path.c'
 
-- 
2.56.0.windows.1

Reply via email to