Skip to content

Commit

Permalink
Remove plain list type annotation in function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
arichardson committed Oct 12, 2023
1 parent fb1957a commit 737b2e6
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pycheribuild/config/defaultconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, option_name, help_message, altname=None, actions=None) -> Non


class DefaultCheribuildConfigLoader(JsonAndCommandLineConfigLoader):
def finalize_options(self, available_targets: list, **kwargs) -> None:
def finalize_options(self, available_targets: "list[str]", **kwargs) -> None:
target_option = self._parser.add_argument("targets", metavar="TARGET", nargs=argparse.ZERO_OR_MORE,
help="The targets to build")
if argcomplete and self.is_completing_arguments:
Expand All @@ -82,7 +82,7 @@ def finalize_options(self, available_targets: list, **kwargs) -> None:


class DefaultCheriConfig(CheriConfig):
def __init__(self, loader: ConfigLoaderBase, available_targets: list) -> None:
def __init__(self, loader: ConfigLoaderBase, available_targets: "list[str]") -> None:
super().__init__(loader, action_class=CheribuildAction)
self.default_action = CheribuildAction.BUILD
# The run mode:
Expand Down
2 changes: 1 addition & 1 deletion pycheribuild/config/jenkinsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _infer_compiler_output_path(config: "JenkinsConfig", _):


class JenkinsConfig(CheriConfig):
def __init__(self, loader: ConfigLoaderBase, available_targets: list) -> None:
def __init__(self, loader: ConfigLoaderBase, available_targets: "list[str]") -> None:
super().__init__(loader, action_class=JenkinsAction)
self.cpu = loader.add_commandline_only_option(
"cpu", default=os.getenv("CPU", "default"),
Expand Down
2 changes: 1 addition & 1 deletion pycheribuild/jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def load(self) -> None:
assert isinstance(self._parsed_args.targets, list)
self._parsed_args.verbose = True

def finalize_options(self, available_targets: list, **kwargs) -> None:
def finalize_options(self, available_targets: "list[str]", **kwargs) -> None:
target_option = self._parser.add_argument(
"targets", metavar="TARGET", nargs=argparse.ZERO_OR_MORE, help="The target to build",
choices=[*available_targets, EXTRACT_SDK_TARGET, RUN_EVERYTHING_TARGET])
Expand Down
6 changes: 3 additions & 3 deletions pycheribuild/projects/cmake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import shutil
import subprocess
from pathlib import Path
from typing import Optional, Sequence
from typing import Optional, Sequence, Union

from .project import MakeCommandKind, Project, _CMakeAndMesonSharedLogic
from .simple_project import _default_stdout_filter
Expand Down Expand Up @@ -63,7 +63,7 @@ class CMakeProject(_CMakeAndMesonSharedLogic):
# 3.13.4 is the minimum version for LLVM and that also allows us to use "cmake --build -j <N>" unconditionally.
_minimum_cmake_or_meson_version: "tuple[int, ...]" = (3, 13, 4)

def _toolchain_file_list_to_str(self, value: list) -> str:
def _toolchain_file_list_to_str(self, value: "list[Union[str, Path]]") -> str:
assert isinstance(value, list), f"Expected a list and not {type(value)}: {value}"
return ";".join(map(str, value))

Expand Down Expand Up @@ -376,7 +376,7 @@ def setup(self) -> None:
LDFLAGS=commandline_to_str(self.default_ldflags + self.LDFLAGS),
)

def set_make_cmd_with_args(self, var, cmd: Path, args: list) -> None:
def set_make_cmd_with_args(self, var, cmd: Path, args: "list[str]") -> None:
value = str(cmd)
if args:
value += " " + self.commandline_to_str(args)
Expand Down
2 changes: 1 addition & 1 deletion pycheribuild/projects/cross/cheribsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,7 @@ def get_default_kernel_abi(self) -> KernelABI:
return kernel_abi

def _get_config_variants(self, platforms: "set[ConfigPlatform]", kernel_abis: "list[KernelABI]",
combine_flags: list, **filter_kwargs) -> "list[CheriBSDConfig]":
combine_flags: "list[str]", **filter_kwargs) -> "list[CheriBSDConfig]":
flag_values = itertools.product([True, False], repeat=len(combine_flags))
combine_tuples = list(itertools.product(platforms, kernel_abis, flag_values))
configs = []
Expand Down
2 changes: 1 addition & 1 deletion pycheribuild/projects/cross/crosscompileproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def add_configure_vars(self, **kwargs):
for k, v in kwargs.items():
self.add_configure_env_arg(k, v)

def set_configure_prog_with_args(self, prog: str, path: Path, args: list):
def set_configure_prog_with_args(self, prog: str, path: Path, args: "list[Union[str, Path]]"):
super().set_configure_prog_with_args(prog, path, args)
if self._configure_supports_variables_on_cmdline:
self.configure_args.append(prog + "=" + self.configure_environment[prog])
Expand Down
2 changes: 1 addition & 1 deletion pycheribuild/projects/disk_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def add_all_files_in_dir(self, root_dir: Path):
def is_x86(self):
return self.crosscompile_target.is_any_x86()

def run_mkimg(self, cmd: list, **kwargs):
def run_mkimg(self, cmd: "list[str]", **kwargs):
if not self.mkimg_cmd or not self.mkimg_cmd.exists():
self.fatal(f"Missing mkimg command ('{self.mkimg_cmd}')! Should be found in FreeBSD build dir.",
fixit_hint="Pass an explicit path to mkimg by setting the MKIMG_CMD environment variable")
Expand Down
4 changes: 2 additions & 2 deletions pycheribuild/projects/meson_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import os
import shutil
from pathlib import Path
from typing import Sequence
from typing import Sequence, Union

from .project import MakeCommandKind, _CMakeAndMesonSharedLogic
from ..config.chericonfig import BuildType
Expand Down Expand Up @@ -136,7 +136,7 @@ def setup(self) -> None:
def needs_configure(self) -> bool:
return not (self.build_dir / "build.ninja").exists()

def _toolchain_file_list_to_str(self, values: list) -> str:
def _toolchain_file_list_to_str(self, values: "list[Union[str, Path]]") -> str:
# The meson toolchain file uses python-style lists
assert all(isinstance(x, (str, Path)) for x in values), \
"All values should be strings/Paths: " + str(values)
Expand Down
8 changes: 4 additions & 4 deletions pycheribuild/projects/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ def add_configure_env_arg(self, arg: str, value: "Union[str,Path]"):
assert not isinstance(value, tuple), ("Wrong type:", type(value))
self.configure_environment[arg] = str(value)

def set_configure_prog_with_args(self, prog: str, path: Path, args: list) -> None:
def set_configure_prog_with_args(self, prog: str, path: Path, args: "list[Union[str, Path]]") -> None:
fullpath = str(path)
if args:
fullpath += " " + self.commandline_to_str(args)
Expand Down Expand Up @@ -1595,7 +1595,7 @@ class _CMakeAndMesonSharedLogic(Project):
class CommandLineArgs:
"""Simple wrapper to distinguish CMake (space-separated string) from Meson (python-style list)"""

def __init__(self, args: list) -> None:
def __init__(self, args: "list[Union[str, Path]]") -> None:
self.args = args

def __str__(self) -> str:
Expand All @@ -1607,7 +1607,7 @@ def __repr__(self) -> str:
class EnvVarPathList:
"""Simple wrapper to distinguish CMake (:-separated string) from Meson (python-style list)"""

def __init__(self, paths: list) -> None:
def __init__(self, paths: "list[str]") -> None:
self.paths = paths

def __str__(self) -> str:
Expand All @@ -1616,7 +1616,7 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return str(self)

def _toolchain_file_list_to_str(self, value: list) -> str:
def _toolchain_file_list_to_str(self, value: "list[Union[str, Path]]") -> str:
raise NotImplementedError()

def _toolchain_file_command_args_to_str(self, value: CommandLineArgs) -> str:
Expand Down
5 changes: 3 additions & 2 deletions pycheribuild/projects/run_fvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ def _fvp_base_command(self, need_tty=True, docker_image=None) -> typing.Tuple[li
else:
return [], self.install_dir / model_relpath

def execute_fvp(self, args: list, disk_image_path: "Optional[Path]" = None, firmware_path: "Optional[Path]" = None,
x11=True, tcp_ports: "Optional[list[int]]" = None, interactive=True, **kwargs) -> CompletedProcess:
def execute_fvp(self, args: "list[str]", disk_image_path: "Optional[Path]" = None,
firmware_path: "Optional[Path]" = None, x11=True, tcp_ports: "Optional[list[int]]" = None,
interactive=True, **kwargs) -> CompletedProcess:
if tcp_ports is None:
tcp_ports = []
display = os.getenv("DISPLAY", None)
Expand Down
2 changes: 1 addition & 1 deletion pycheribuild/projects/sail.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def run_in_ocaml_env(self, command: str, cwd=None, print_verbose_only=False, **k
script = "eval `opam config env`\n" + command + "\n"
return self.run_shell_script(script, cwd=cwd, print_verbose_only=print_verbose_only, env=opam_env, **kwargs)

def run_command_in_ocaml_env(self, command: list, cwd=None, print_verbose_only=False, **kwargs):
def run_command_in_ocaml_env(self, command: "list[Union[str, Path]]", cwd=None, print_verbose_only=False, **kwargs):
self._ensure_correct_switch()
opam_env, cwd = self._run_in_ocaml_env_prepare(cwd=cwd)
# for opam commands we don't need to prepend opam exec --
Expand Down
2 changes: 1 addition & 1 deletion test-scripts/run_bodiagsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def check_all_cases_parsed(self):
def error(self, *args):
print(self.test_prefix, "ERROR:", *args, file=sys.stderr)

def handle_testcase(self, o: Path, tools: list):
def handle_testcase(self, o: Path, tools: "list[str]"):
stem = o.stem
assert stem.startswith(self.test_prefix), stem
exit_code_str = o.read_text(encoding="utf-8", errors="replace").rstrip()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_argument_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ def test_freebsd_toolchains_cheribsd_purecap():
pytest.param("sqlite-native", [], "sqlite-native-build"),
],
)
def test_default_build_dir(target: str, args: list, expected: str):
def test_default_build_dir(target: str, args: "list[str]", expected: str):
# Check that the cheribsd build dir is correct
config = _parse_arguments(args)
target = target_manager.get_target(target, config=config, caller="test_default_arch")
Expand Down Expand Up @@ -1067,7 +1067,7 @@ def test_default_build_dir(target: str, args: list, expected: str):
pytest.param("freebsd-riscv64", [], "sdk/sysroot-freebsd-riscv64", "freebsd-riscv64"),
],
)
def test_default_rootfs_and_sysroot_dir(target: str, args: list, expected_sysroot: str, expected_rootfs: str):
def test_default_rootfs_and_sysroot_dir(target: str, args: "list[str]", expected_sysroot: str, expected_rootfs: str):
# Check that the cheribsd build dir is correct
config = _parse_arguments(args)
project = _get_target_instance(target, config, BuildFreeBSD)
Expand Down

0 comments on commit 737b2e6

Please sign in to comment.