diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-11-04 11:17:57 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-11-28 12:19:43 +0100 |
commit | 8b44905d1784c95bd80331aa91cc9fbe2b6ee04a (patch) | |
tree | 27d9200b71d11742315a923cc972a867572dd3bf /bin/bootstrap-traverser.py | |
parent | 9dc61e9faca5e8b05a1a2a2eed83a5468aeb6202 (diff) | |
download | justbuild-8b44905d1784c95bd80331aa91cc9fbe2b6ee04a.tar.gz |
bin scripts: Use the NoReturn type hint
The NoReturn type hint should be used to ensure the return type of
methods calling no-return methods are not falsely enforced to an
Optional return type.
Add the NoReturn type hint as needed and clear up existing Optional
returns together with any corresponding casts affected by the
above.
While there, also fix formatting.
Diffstat (limited to 'bin/bootstrap-traverser.py')
-rwxr-xr-x | bin/bootstrap-traverser.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/bin/bootstrap-traverser.py b/bin/bootstrap-traverser.py index 9b82b338..1598c842 100755 --- a/bin/bootstrap-traverser.py +++ b/bin/bootstrap-traverser.py @@ -19,7 +19,7 @@ import os import shutil import subprocess import sys -from typing import Any, Dict, List, Optional, cast +from typing import Any, Dict, List, NoReturn, cast from argparse import ArgumentParser @@ -32,7 +32,7 @@ def log(*args: str, **kwargs: Any) -> None: print(*args, file=sys.stderr, **kwargs) -def fail(s: str) -> None: +def fail(s: str) -> NoReturn: log(s) sys.exit(1) @@ -66,7 +66,7 @@ def link(src: str, dest: str) -> None: os.symlink(src, dest) -def build_local(desc: Json, *, root: str, config: Json) -> Optional[str]: +def build_local(desc: Json, *, root: str, config: Json) -> str: repo_name = desc["data"]["repository"] repo: List[str] = config["repositories"][repo_name]["workspace_root"] rel_path = desc["data"]["path"] @@ -83,7 +83,7 @@ def build_tree(desc: Json, *, config: Json, root: str, graph: Json) -> str: tree_dir_tmp = tree_dir + ".tmp" tree_desc = graph["trees"][tree_id] for location, desc in tree_desc.items(): - link(cast(str, build(desc, config=config, root=root, graph=graph)), + link(build(desc, config=config, root=root, graph=graph), os.path.join(tree_dir_tmp, location)) # correctly handle the empty tree os.makedirs(tree_dir_tmp, exist_ok=True) @@ -98,7 +98,7 @@ def run_action(action_id: str, *, config: Json, root: str, graph: Json) -> str: os.makedirs(action_dir) action_desc = graph["actions"][action_id] for location, desc in action_desc.get("input", {}).items(): - link(cast(str, build(desc, config=config, root=root, graph=graph)), + link(build(desc, config=config, root=root, graph=graph), os.path.join(action_dir, location)) cmd = action_desc["command"] env = action_desc.get("env") @@ -121,7 +121,7 @@ def build_action(desc: Json, *, config: Json, root: str, graph: Json) -> str: return os.path.join(action_dir, desc["data"]["path"]) -def build(desc: Json, *, config: Json, root: str, graph: Json) -> Optional[str]: +def build(desc: Json, *, config: Json, root: str, graph: Json) -> str: if desc["type"] == "TREE": return build_tree(desc, config=config, root=root, graph=graph) if desc["type"] == "ACTION": @@ -139,7 +139,7 @@ def traverse(*, graph: Json, to_build: Json, out: str, root: str, os.makedirs(root, exist_ok=True) create_blobs(graph["blobs"], root=root) for location, artifact in to_build.items(): - link(cast(str, build(artifact, config=config, root=root, graph=graph)), + link(build(artifact, config=config, root=root, graph=graph), os.path.join(out, location)) |