summaryrefslogtreecommitdiff
path: root/mesonbuild/options.py
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-05-07 14:10:51 +0200
committerDylan Baker <dylan@pnwbakers.com>2025-05-07 09:43:43 -0700
commitc1b7ef4218f12905641f1cb1503c8b9b3542e983 (patch)
tree48f8fd9e8501b9867aa75505ae60207fa8e39624 /mesonbuild/options.py
parenta46371f6d8c01953d8d8bd3d8e86594cc3c8e37f (diff)
downloadmeson-c1b7ef4218f12905641f1cb1503c8b9b3542e983.tar.gz
options: fix "deprecated" with dictionary argument and non-string types
Since opt.deprecated is a dictionary with string keys, the lookup must use str() around the user-provided value; with some care because booleans will be the meson-ic 'true' and 'false' instead of Python's 'True' and 'False'. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild/options.py')
-rw-r--r--mesonbuild/options.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/mesonbuild/options.py b/mesonbuild/options.py
index f897916c7..2d96380c4 100644
--- a/mesonbuild/options.py
+++ b/mesonbuild/options.py
@@ -327,7 +327,13 @@ class UserOption(T.Generic[_T], HoldableObject):
# Final isn't technically allowed in a __post_init__ method
self.default: Final[_T] = self.value # type: ignore[misc]
- def listify(self, value: T.Any) -> T.List[T.Any]:
+ def listify(self, value: ElementaryOptionValues) -> T.List[str]:
+ if isinstance(value, list):
+ return value
+ if isinstance(value, bool):
+ return ['true'] if value else ['false']
+ if isinstance(value, int):
+ return [str(value)]
return [value]
def printable_value(self) -> ElementaryOptionValues:
@@ -503,7 +509,7 @@ class UserArrayOption(UserOption[T.List[_T]]):
@dataclasses.dataclass
class UserStringArrayOption(UserArrayOption[str]):
- def listify(self, value: T.Any) -> T.List[T.Any]:
+ def listify(self, value: ElementaryOptionValues) -> T.List[str]:
try:
return listify_array_value(value, self.split_args)
except MesonException as e:
@@ -1005,7 +1011,7 @@ class OptionStore:
if v in opt.deprecated:
mlog.deprecation(f'Option {key.name!r} value {v!r} is deprecated')
elif isinstance(opt.deprecated, dict):
- def replace(v: T.Any) -> T.Any:
+ def replace(v: str) -> str:
assert isinstance(opt.deprecated, dict) # No, Mypy can not tell this from two lines above
newvalue = opt.deprecated.get(v)
if newvalue is not None: