gdb: copyright.py cleanup

Message ID 20240425173847.50357-1-simon.marchi@efficios.com
State New
Headers
Series gdb: copyright.py cleanup |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Simon Marchi April 25, 2024, 5:38 p.m. UTC
  - Make the top comment a proper comment instead of a string, to avoid
   "invalid escape sequence" warnings due to `\*`.
 - Remove `datetime` import.
 - Add type annotations.  Use `type: ignore` comments in some places to
   work around the fact that `BY_HAND` has an "empty tuple" type.

Change-Id: I5c2444b794b1138c7760ec5a221f298a8b43f7d4
---
 gdb/copyright.py | 39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)


base-commit: 5b9707eb872ad4cb50c98d396d16f110070a44ca
  

Patch

diff --git a/gdb/copyright.py b/gdb/copyright.py
index 2c9ea3c1d591..74d5cb9994d9 100755
--- a/gdb/copyright.py
+++ b/gdb/copyright.py
@@ -17,21 +17,17 @@ 
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-"""copyright.py
-
-This script updates the list of years in the copyright notices in
-most files maintained by the GDB project.
-
-Usage: cd src/gdb && ./copyright.py
-
-Always review the output of this script before committing it!
-A useful command to review the output is:
-    % filterdiff -x \*.c -x \*.cc -x \*.h -x \*.exp updates.diff
-This removes the bulk of the changes which are most likely to be correct.
-"""
+# This script updates the list of years in the copyright notices in
+# most files maintained by the GDB project.
+#
+# Usage: cd src/gdb && ./copyright.py
+#
+# Always review the output of this script before committing it!
+# A useful command to review the output is:
+#     % filterdiff -x \*.c -x \*.cc -x \*.h -x \*.exp updates.diff
+# This removes the bulk of the changes which are most likely to be correct.
 
 import argparse
-import datetime
 import locale
 import os
 import os.path
@@ -40,14 +36,14 @@  import sys
 from typing import List, Optional
 
 
-def get_update_list():
+def get_update_list() -> list[str]:
     """Return the list of files to update.
 
     Assumes that the current working directory when called is the root
     of the GDB source tree (NOT the gdb/ subdirectory!).  The names of
     the files are relative to that root directory.
     """
-    result = []
+    result: list[str] = []
     for gdb_dir in (
         "gdb",
         "gdbserver",
@@ -63,7 +59,8 @@  def get_update_list():
                     dirname in EXCLUDE_ALL_LIST
                     or reldirname in EXCLUDE_LIST
                     or reldirname in NOT_FSF_LIST
-                    or reldirname in BY_HAND
+                    # Use `type: ignore` to avoid an `always evaluate to False` warning
+                    or reldirname in BY_HAND  # type: ignore
                 ):
                     # Prune this directory from our search list.
                     dirs.remove(dirname)
@@ -73,7 +70,7 @@  def get_update_list():
                     filename in EXCLUDE_ALL_LIST
                     or relpath in EXCLUDE_LIST
                     or relpath in NOT_FSF_LIST
-                    or relpath in BY_HAND
+                    or relpath in BY_HAND  # type: ignore
                 ):
                     # Ignore this file.
                     pass
@@ -82,7 +79,7 @@  def get_update_list():
     return result
 
 
-def update_files(update_list):
+def update_files(update_list: list[str]):
     """Update the copyright header of the files in the given list.
 
     We use gnulib's update-copyright script for that.
@@ -127,7 +124,7 @@  def update_files(update_list):
             print("*** " + line)
 
 
-def may_have_copyright_notice(filename):
+def may_have_copyright_notice(filename: str):
     """Check that the given file does not seem to have a copyright notice.
 
     The filename is relative to the root directory.
@@ -197,8 +194,8 @@  def main(argv: List[str]) -> Optional[int]:
         print(
             "\033[31mREMINDER: The following files must be updated by hand." "\033[0m"
         )
-        for filename in BY_HAND:
-            print("  ", filename)
+        for filename in BY_HAND:  # type: ignore
+            print("  ", filename)  # type: ignore
 
 
 ############################################################################