summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-10-07 15:20:47 +0200
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-10-29 18:59:30 +0200
commit855af6f69ad0bc87c1d898688286265138c36061 (patch)
tree84fb2b7647d9429883c14c792b1931f973574570
parent1f0644f9c60eb8c4db7057db50f3316575d06b76 (diff)
downloadmeson-855af6f69ad0bc87c1d898688286265138c36061.tar.gz
cmdline: fix typing issues
Command line handling had almost complete annotations, but some were missing (especially argparse related types) or wrong (the native and cross files passed to the CmdLineFileParser). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--mesonbuild/cmdline.py13
-rwxr-xr-xrun_mypy.py1
2 files changed, 7 insertions, 7 deletions
diff --git a/mesonbuild/cmdline.py b/mesonbuild/cmdline.py
index efa4a2f4c..04f749678 100644
--- a/mesonbuild/cmdline.py
+++ b/mesonbuild/cmdline.py
@@ -9,7 +9,6 @@ import configparser
import os
import shlex
import typing as T
-from collections import OrderedDict
from itertools import chain
from . import options
@@ -78,14 +77,14 @@ def write_cmd_line_file(build_dir: str, options: SharedCMDOptions) -> None:
filename = get_cmd_line_file(build_dir)
config = CmdLineFileParser()
- properties: OrderedDict[str, str] = OrderedDict()
+ properties: T.Dict[str, T.List[str]] = {}
if options.cross_file:
properties['cross_file'] = options.cross_file
if options.native_file:
properties['native_file'] = options.native_file
config['options'] = {str(k): str(v) for k, v in options.cmd_line_options.items()}
- config['properties'] = properties
+ config['properties'] = {k: repr(v) for k, v in properties.items()}
with open(filename, 'w', encoding='utf-8') as f:
config.write(f)
@@ -117,12 +116,12 @@ class KeyNoneAction(argparse.Action):
Custom argparse Action that stores values in a dictionary as keys with value None.
"""
- def __init__(self, option_strings, dest, nargs=None, **kwargs: object) -> None:
+ def __init__(self, option_strings: str, dest: str, nargs: T.Optional[T.Union[int, str]] = None, **kwargs: T.Any) -> None:
assert nargs is None or nargs == 1
super().__init__(option_strings, dest, nargs=1, **kwargs)
def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespace,
- arg: T.List[str], option_string: str = None) -> None:
+ arg: T.List[str], option_string: str = None) -> None: # type: ignore[override]
current_dict = getattr(namespace, self.dest)
if current_dict is None:
current_dict = {}
@@ -137,12 +136,12 @@ class KeyValueAction(argparse.Action):
Custom argparse Action that parses KEY=VAL arguments and stores them in a dictionary.
"""
- def __init__(self, option_strings, dest, nargs=None, **kwargs: object) -> None:
+ def __init__(self, option_strings: str, dest: str, nargs: T.Optional[T.Union[int, str]] = None, **kwargs: T.Any) -> None:
assert nargs is None or nargs == 1
super().__init__(option_strings, dest, nargs=1, **kwargs)
def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespace,
- arg: T.List[str], option_string: str = None) -> None:
+ arg: T.List[str], option_string: str = None) -> None: # type: ignore[override]
current_dict = getattr(namespace, self.dest)
if current_dict is None:
current_dict = {}
diff --git a/run_mypy.py b/run_mypy.py
index eb004c381..038e391b7 100755
--- a/run_mypy.py
+++ b/run_mypy.py
@@ -30,6 +30,7 @@ modules = [
'mesonbuild/arglist.py',
'mesonbuild/backend/backends.py',
'mesonbuild/backend/nonebackend.py',
+ 'mesonbuild/cmdline.py',
# 'mesonbuild/coredata.py',
'mesonbuild/depfile.py',
'mesonbuild/envconfig.py',