From aba5221e008643361d02e1b9f6446856e73a99e7 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 31 Jul 2026 14:47:56 +0200 Subject: [PATCH] options: cleanup argparse_prefixed_default It is used even outside argparse, and it also does not need an isinstance check. Signed-off-by: Paolo Bonzini --- mesonbuild/cmdline.py | 2 +- mesonbuild/options.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/mesonbuild/cmdline.py b/mesonbuild/cmdline.py index d495a122f..ade20d778 100644 --- a/mesonbuild/cmdline.py +++ b/mesonbuild/cmdline.py @@ -158,7 +158,7 @@ class BuiltinAction(argparse.Action): kwargs['nargs'] = 1 if help_suffix: help_suffix += ', ' - help_suffix += 'default: ' + str(options.argparse_prefixed_default(option, name=option_key)) + help_suffix += 'default: ' + str(options.prefixed_default(option, name=option_key)) if isinstance(option, (options.EnumeratedUserOption, options.UserArrayOption)): kwargs['choices'] = option.choices diff --git a/mesonbuild/options.py b/mesonbuild/options.py index 1f57f56bb..1d8c58974 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -646,13 +646,11 @@ def argparse_name_to_arg(name: str) -> str: return '--' + name.replace('_', '-') -def argparse_prefixed_default(opt: AnyOptionType, name: OptionKey, prefix: str = '') -> ElementaryOptionValues: - if isinstance(opt, (UserComboOption, UserIntegerOption, UserUmaskOption)): - return T.cast('ElementaryOptionValues', opt.default) +def prefixed_default(opt: AnyOptionType, name: OptionKey, prefix: str = '') -> ElementaryOptionValues: try: return BUILTIN_DIR_NOPREFIX_OPTIONS[name][prefix] except KeyError: - return T.cast('ElementaryOptionValues', opt.default) + return opt.default # Update `docs/markdown/Builtin-options.md` after changing the options below @@ -942,7 +940,7 @@ class OptionStore: # Create a copy of the object, as we're going to mutate it opt = copy.copy(opt) assert key.subproject is None - new_value = argparse_prefixed_default(opt, key, default_prefix()) + new_value = prefixed_default(opt, key, default_prefix()) opt.set_value(new_value) modulename = key.get_module_prefix()