aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter/interpreterobjects.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-12-06 14:58:38 -0800
committerEli Schwartz <eschwartz93@gmail.com>2022-01-18 17:53:29 -0500
commitbaa9ecb1c465b5b081a4a2ab9861beda5030fddf (patch)
treec7872eac068b633e44d8359b0ddb70a2fa0bb488 /mesonbuild/interpreter/interpreterobjects.py
parent65558445aee30517f8abe94dadcd3ab57dddf56a (diff)
downloadmeson-baa9ecb1c465b5b081a4a2ab9861beda5030fddf.zip
meson-baa9ecb1c465b5b081a4a2ab9861beda5030fddf.tar.gz
meson-baa9ecb1c465b5b081a4a2ab9861beda5030fddf.tar.bz2
interpreterobjects: use typed_args for configuration_data.get
Diffstat (limited to 'mesonbuild/interpreter/interpreterobjects.py')
-rw-r--r--mesonbuild/interpreter/interpreterobjects.py18
1 files changed, 6 insertions, 12 deletions
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py
index ef55f24..a1bbd39 100644
--- a/mesonbuild/interpreter/interpreterobjects.py
+++ b/mesonbuild/interpreter/interpreterobjects.py
@@ -355,21 +355,15 @@ class ConfigurationDataObject(MutableInterpreterObject, MesonInterpreterObject):
@FeatureNew('configuration_data.get()', '0.38.0')
@noArgsFlattening
- def get_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> T.Union[str, int, bool]:
- if len(args) < 1 or len(args) > 2:
- raise InterpreterException('Get method takes one or two arguments.')
- if not isinstance(args[0], str):
- raise InterpreterException('The variable name must be a string.')
+ @typed_pos_args('configuration_data.get', str, optargs=[(str, int, bool)])
+ @noKwargs
+ def get_method(self, args: T.Tuple[str, T.Optional[T.Union[str, int, bool]]],
+ kwargs: TYPE_kwargs) -> T.Union[str, int, bool]:
name = args[0]
if name in self.conf_data:
return self.conf_data.get(name)[0]
- if len(args) > 1:
- # Assertion does not work because setting other values is still
- # supported, but deprecated. Use T.cast in the meantime (even though
- # this is a lie).
- # TODO: Fix this once the deprecation is removed
- # assert isinstance(args[1], (int, str, bool))
- return T.cast(T.Union[str, int, bool], args[1])
+ elif args[1] is not None:
+ return args[1]
raise InterpreterException(f'Entry {name} not in configuration data.')
@FeatureNew('configuration_data.get_unquoted()', '0.44.0')