From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 1/2] gdb: make typing strict in gdb/copyright.py
Date: Wed, 9 Apr 2025 10:49:58 -0400 [thread overview]
Message-ID: <20250409145002.30405-1-simon.marchi@efficios.com> (raw)
Add `pyright: strict` at the top of the file, then adjust the fallouts.
This annotation is understood by pyright, and thus any IDE using pyright
behind the scenes (VSCode and probably others).
I presume that any GDB developer running this script is using a recent
enough version of Python, so specify the type annotations using the
actual types when possible (e.g. `list[str]` instead of
`typing.List[str]`). I believe this required Python 3.9.
Change-Id: I3698e28555e236a03126d4cd010dae4b5647ce48
---
gdb/copyright.py | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/gdb/copyright.py b/gdb/copyright.py
index 5ec9944aae20..1c81358f1384 100755
--- a/gdb/copyright.py
+++ b/gdb/copyright.py
@@ -30,13 +30,15 @@
#
# This removes the bulk of the changes which are most likely to be correct.
+# pyright: strict
+
import argparse
import locale
import os
import os.path
import subprocess
import sys
-from typing import List, Optional
+from typing import Iterable
def get_update_list():
@@ -66,7 +68,7 @@ def get_update_list():
.split("\0")
)
- def include_file(filename):
+ def include_file(filename: str):
(dirname, basename) = os.path.split(filename)
dirbasename = os.path.basename(dirname)
return not (
@@ -83,7 +85,7 @@ def get_update_list():
return filter(include_file, result)
-def update_files(update_list):
+def update_files(update_list: Iterable[str]):
"""Update the copyright header of the files in the given list.
We use gnulib's update-copyright script for that.
@@ -128,7 +130,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.
@@ -166,7 +168,7 @@ def get_parser() -> argparse.ArgumentParser:
return parser
-def main(argv: List[str]) -> Optional[int]:
+def main(argv: list[str]) -> int | None:
"""The main subprogram."""
parser = get_parser()
_ = parser.parse_args(argv)
@@ -242,9 +244,9 @@ EXCLUDE_ALL_LIST = (
)
# The list of files to update by hand.
-BY_HAND = (
+BY_HAND: list[str] = [
# Nothing at the moment :-).
-)
+]
# Files containing multiple copyright headers. This script is only
# fixing the first one it finds, so we need to finish the update
base-commit: 2bbe439e72916c7d61bf0b7a8c898426bfabc0ba
--
2.49.0
next reply other threads:[~2025-04-09 14:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 14:49 Simon Marchi [this message]
2025-04-09 14:49 ` [PATCH 2/2] gdb: fix bugs in gdb/copyright.py, make it use glob patterns Simon Marchi
2025-04-11 13:52 ` Guinevere Larsen
2025-04-11 14:14 ` Simon Marchi
2025-04-11 14:45 ` Guinevere Larsen
2025-04-11 15:28 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250409145002.30405-1-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox