forked from Imagelibrary/binutils-gdb
gdb: make typing strict in gdb/copyright.py
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 Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
This commit is contained in:
@@ -30,13 +30,15 @@
|
|||||||
#
|
#
|
||||||
# This removes the bulk of the changes which are most likely to be correct.
|
# This removes the bulk of the changes which are most likely to be correct.
|
||||||
|
|
||||||
|
# pyright: strict
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import locale
|
import locale
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from typing import List, Optional
|
from typing import Iterable
|
||||||
|
|
||||||
|
|
||||||
def get_update_list():
|
def get_update_list():
|
||||||
@@ -66,7 +68,7 @@ def get_update_list():
|
|||||||
.split("\0")
|
.split("\0")
|
||||||
)
|
)
|
||||||
|
|
||||||
def include_file(filename):
|
def include_file(filename: str):
|
||||||
(dirname, basename) = os.path.split(filename)
|
(dirname, basename) = os.path.split(filename)
|
||||||
dirbasename = os.path.basename(dirname)
|
dirbasename = os.path.basename(dirname)
|
||||||
return not (
|
return not (
|
||||||
@@ -83,7 +85,7 @@ def get_update_list():
|
|||||||
return filter(include_file, result)
|
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.
|
"""Update the copyright header of the files in the given list.
|
||||||
|
|
||||||
We use gnulib's update-copyright script for that.
|
We use gnulib's update-copyright script for that.
|
||||||
@@ -128,7 +130,7 @@ def update_files(update_list):
|
|||||||
print("*** " + line)
|
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.
|
"""Check that the given file does not seem to have a copyright notice.
|
||||||
|
|
||||||
The filename is relative to the root directory.
|
The filename is relative to the root directory.
|
||||||
@@ -166,7 +168,7 @@ def get_parser() -> argparse.ArgumentParser:
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def main(argv: List[str]) -> Optional[int]:
|
def main(argv: list[str]) -> int | None:
|
||||||
"""The main subprogram."""
|
"""The main subprogram."""
|
||||||
parser = get_parser()
|
parser = get_parser()
|
||||||
_ = parser.parse_args(argv)
|
_ = parser.parse_args(argv)
|
||||||
@@ -242,7 +244,7 @@ EXCLUDE_ALL_LIST = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
# The list of files to update by hand.
|
# The list of files to update by hand.
|
||||||
BY_HAND = (
|
BY_HAND: tuple[str, ...] = (
|
||||||
# Nothing at the moment :-).
|
# Nothing at the moment :-).
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user