Skip to content

Commit

Permalink
options: fix typing of add_to_argparse
Browse files Browse the repository at this point in the history
Which wants a string, but then passes that string to a function that
wants an OptionKey, which means that we'll always miss the lookup in
BULITIN_DIR_NOPREFIX_OPTIONS, and return the default. The only case this
gets used we cast an OptionKey to str, and then pass that. So instead,
do the cast inside the function when necessary and pass the OptionKey
  • Loading branch information
dcbaker committed Aug 30, 2024
1 parent 4888979 commit 0088e1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,10 @@ def save(obj: CoreData, build_dir: str) -> str:

def register_builtin_arguments(parser: argparse.ArgumentParser) -> None:
for n, b in options.BUILTIN_OPTIONS.items():
b.add_to_argparse(str(n), parser, '')
b.add_to_argparse(n, parser, '')
for n, b in options.BUILTIN_OPTIONS_PER_MACHINE.items():
b.add_to_argparse(str(n), parser, ' (just for host machine)')
b.add_to_argparse(str(n.as_build()), parser, ' (just for build machine)')
b.add_to_argparse(n, parser, ' (just for host machine)')
b.add_to_argparse(n.as_build(), parser, ' (just for build machine)')
parser.add_argument('-D', action='append', dest='projectoptions', default=[], metavar="option",
help='Set the value of an option, can be used several times to set multiple options.')

Expand Down
6 changes: 3 additions & 3 deletions mesonbuild/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def prefixed_default(self, name: 'OptionKey', prefix: str = '') -> T.Any:
pass
return self.default

def add_to_argparse(self, name: str, parser: argparse.ArgumentParser, help_suffix: str) -> None:
def add_to_argparse(self, name: OptionKey, parser: argparse.ArgumentParser, help_suffix: str) -> None:
kwargs: ArgparseKWs = {}

c = self._argparse_choices()
Expand All @@ -601,9 +601,9 @@ def add_to_argparse(self, name: str, parser: argparse.ArgumentParser, help_suffi
if c and not b:
kwargs['choices'] = c
kwargs['default'] = argparse.SUPPRESS
kwargs['dest'] = name
kwargs['dest'] = str(name)

cmdline_name = self.argparse_name_to_arg(name)
cmdline_name = self.argparse_name_to_arg(str(name))
parser.add_argument(cmdline_name, help=h + help_suffix, **kwargs)


Expand Down

0 comments on commit 0088e1d

Please sign in to comment.