diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-12-06 14:20:31 -0800 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2022-01-18 17:53:29 -0500 |
commit | ab9c0c17356eb05078f1ae5d876638b4620d0148 (patch) | |
tree | 4cd47733a2eb0b5850a70066638ca815334b39e6 /mesonbuild | |
parent | 55055c3e0ecd7cd0458632393b1ddca68bed8900 (diff) | |
download | meson-ab9c0c17356eb05078f1ae5d876638b4620d0148.zip meson-ab9c0c17356eb05078f1ae5d876638b4620d0148.tar.gz meson-ab9c0c17356eb05078f1ae5d876638b4620d0148.tar.bz2 |
interpreterobjects: use typed_kwargs for FeatureOption.require
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/interpreter/interpreterobjects.py | 19 | ||||
-rw-r--r-- | mesonbuild/interpreter/kwargs.py | 5 |
2 files changed, 14 insertions, 10 deletions
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index 727d097..fe24aef 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -124,21 +124,20 @@ class FeatureOptionHolder(ObjectHolder[coredata.UserFeatureOption]): def auto_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> bool: return self.value == 'auto' - @permittedKwargs({'error_message'}) @typed_pos_args('feature_option.require', bool) - def require_method(self, args: T.Tuple[bool], kwargs: TYPE_kwargs) -> coredata.UserFeatureOption: - error_message = kwargs.pop('error_message', '') - if error_message and not isinstance(error_message, str): - raise InterpreterException("Error message must be a string.") + @typed_kwargs( + 'feature_option.require', + KwargInfo('error_message', (str, NoneType)) + ) + def require_method(self, args: T.Tuple[bool], kwargs: 'kwargs.FeatureOptionRequire') -> coredata.UserFeatureOption: if args[0]: return copy.deepcopy(self.held_object) - assert isinstance(error_message, str) if self.value == 'enabled': - prefix = f'Feature {self.held_object.name} cannot be enabled' - if error_message: - prefix += ': ' - raise InterpreterException(prefix + error_message) + err_msg = f'Feature {self.held_object.name} cannot be enabled' + if kwargs['error_message']: + err_msg += f': {kwargs["error_message"]}' + raise InterpreterException(err_msg) return self.as_disabled() @noKwargs diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index 6056329..439e866 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -239,3 +239,8 @@ class RunCommand(TypedDict): check: bool capture: T.Optional[bool] env: build.EnvironmentVariables + + +class FeatureOptionRequire(TypedDict): + + error_message: T.Optional[str] |