diff --git a/.mypy.ini b/.mypy.ini index c85c6d632..3373bdb28 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -60,6 +60,9 @@ strict_optional = True [mypy-mesonbuild.mesondata] strict_optional = True +[mypy-mesonbuild.mesonmain] +strict_optional = True + [mypy-mesonbuild.mlog] strict_optional = True diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index ee2f5c8a8..a087ad277 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -57,7 +57,7 @@ def errorhandler(e: Exception, command: str) -> int: elif isinstance(e, OSError): mlog.exception(Exception("Unhandled python OSError. This is probably not a Meson bug, " "but an issue with your build environment.")) - return e.errno + return e.errno or 0 else: # Exception msg = 'Unhandled python exception' if all(getattr(e, a, None) is not None for a in ['file', 'lineno', 'colno']): @@ -126,7 +126,8 @@ class CommandLineParser: help_msg=argparse.SUPPRESS) def add_command(self, name: str, add_arguments_func: T.Callable[[argparse.ArgumentParser], None], - run_func: T.Callable[[argparse.Namespace], int], help_msg: str, aliases: T.List[str] = None) -> None: + run_func: T.Callable[[argparse.Namespace], int], help_msg: str, + aliases: T.List[str] | None = None) -> None: aliases = aliases or [] # FIXME: Cannot have hidden subparser: # https://bugs.python.org/issue22848 @@ -185,7 +186,7 @@ class CommandLineParser: command = None from . import mesonlib - args = mesonlib.expand_arguments(args) + args = mesonlib.unwrap_err(mesonlib.expand_arguments(args), 'Failed to expand arguments') options = T.cast('MesonMainCMDOptions', parser.parse_args(args)) if command is None: diff --git a/mesonbuild/scripts/env2mfile.py b/mesonbuild/scripts/env2mfile.py index ee973a923..2703bdde9 100755 --- a/mesonbuild/scripts/env2mfile.py +++ b/mesonbuild/scripts/env2mfile.py @@ -537,7 +537,7 @@ class AndroidDetector: ofile.write("endian = 'little'\n") -def run(options: T.Any) -> None: +def run(options: argparse.Namespace) -> int: mlog.notice('This functionality is experimental and subject to change.') if options.cross: if options.use_for_build: @@ -554,3 +554,5 @@ def run(options: T.Any) -> None: ad.detect_toolchains() else: raise ValueError("Encountered unreachable code-path") + + return 0 diff --git a/mesonbuild/scripts/reprotest.py b/mesonbuild/scripts/reprotest.py index fc9315c8f..ef9a4cb72 100755 --- a/mesonbuild/scripts/reprotest.py +++ b/mesonbuild/scripts/reprotest.py @@ -114,10 +114,10 @@ class ReproTester: self.check_contents('buildrepro', 'buildrepro.1st', True) self.check_contents('buildrepro.1st', 'buildrepro', False) -def run(options: T.Any) -> None: +def run(options: argparse.Namespace) -> int: rt = ReproTester(options) try: - sys.exit(rt.run()) + return rt.run() except Exception as e: print(e) - sys.exit(1) + return 1