From 294eca343d072a18a22d9a0cf932a8e97bdb16ed Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 28 Feb 2025 09:18:01 -0800 Subject: options: store the default value in the class Initially this is just used for getting builtin option default values, but it could be extended to show the default value of an option in the summary and in the introspection API. --- mesonbuild/options.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mesonbuild/options.py b/mesonbuild/options.py index ab4fcbe0c..a84712783 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -33,7 +33,7 @@ from .mesonlib import ( from . import mlog if T.TYPE_CHECKING: - from typing_extensions import Literal, TypeAlias, TypedDict + from typing_extensions import Literal, Final, TypeAlias, TypedDict DeprecatedType: TypeAlias = T.Union[bool, str, T.Dict[str, str], T.List[str]] AnyOptionType: TypeAlias = T.Union[ @@ -324,6 +324,8 @@ class UserOption(T.Generic[_T], HoldableObject): def __post_init__(self, value_: _T) -> None: self.value = self.validate_value(value_) + # 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]: return [value] -- cgit v1.2.3