mesonmain: Turn on mypy strict optional

This commit is contained in:
Dylan Baker authored and Paolo Bonzini committed 2026-06-18 17:37:02 +02:00
1 parent 0c106b2b8a
commit 7b6de79f06
4 files changed
+13 -7

No files matched your search

+3
View File
@@ -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
+4 -3
View File
@@ -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:
+3 -1
View File
@@ -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
+3 -3
View File
@@ -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