From 8b44905d1784c95bd80331aa91cc9fbe2b6ee04a Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 4 Nov 2024 11:17:57 +0100 Subject: 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. --- bin/just-mr.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'bin/just-mr.py') diff --git a/bin/just-mr.py b/bin/just-mr.py index 21413546..4b79c295 100755 --- a/bin/just-mr.py +++ b/bin/just-mr.py @@ -22,7 +22,7 @@ import sys import tempfile import time import zlib -from typing import Any, Dict, List, Optional, Set, Tuple, Union, cast +from typing import Any, Dict, List, NoReturn, Optional, Set, Tuple, Union, cast from argparse import ArgumentParser from pathlib import Path @@ -140,7 +140,7 @@ def log(*args: str, **kwargs: Any) -> None: print(*args, file=sys.stderr, **kwargs) -def fail(s: str, exit_code: int = 65) -> None: +def fail(s: str, exit_code: int = 65) -> NoReturn: log(f"Error: {s}") sys.exit(exit_code) @@ -701,7 +701,7 @@ def distdir_tree_id_file(content: str) -> str: content) -def distdir_checkout(desc: Json, repos: Json): +def distdir_checkout(desc: Json, repos: Json) -> List[str]: """ Logic for processing the distdir repo type. """ content: Dict[str, str] = {} @@ -783,7 +783,7 @@ def distdir_checkout(desc: Json, repos: Json): ] -def checkout(desc: Json, *, name: str, repos: Json) -> Optional[List[str]]: +def checkout(desc: Json, *, name: str, repos: Json) -> List[str]: repo_desc = resolve_repo(desc, repos=repos) repo_type = repo_desc.get("type") if repo_type == "git": @@ -965,8 +965,7 @@ def fetch(*, return os.path.commonpath([path, base]) == base # warn if fetch_dir is in invocation workspace - if g_WORKSPACE_ROOT and is_subpath(cast(str, fetch_dir), - g_WORKSPACE_ROOT): + if g_WORKSPACE_ROOT and is_subpath(fetch_dir, g_WORKSPACE_ROOT): repo = repos.get(main, {}).get("repository", {}) repo_path = repo.get("path", None) if repo_path is not None and repo.get("type", None) == "file": @@ -993,7 +992,7 @@ Warning: Writing distribution files to workspace location '{fetch_dir}', print("%r --> %r (content: %s)" % (repo, distfile, content)) archive_fetch(repo_desc, content) shutil.copyfile(cas_path(content), - os.path.join(cast(str, fetch_dir), distfile)) + os.path.join(fetch_dir, distfile)) sys.exit(0) -- cgit v1.2.3