aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules/keyval.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-11-23 13:19:49 -0800
committerDylan Baker <dylan@pnwbakers.com>2021-11-23 13:20:11 -0800
commit904771c4e1a297dc37676cd9a5fdec826addfc44 (patch)
tree9165aa46992dce3b91e05a08d8ef7458512698a2 /mesonbuild/modules/keyval.py
parent717d03af1caf35ea73356ef8135f26f3aea98277 (diff)
downloadmeson-904771c4e1a297dc37676cd9a5fdec826addfc44.zip
meson-904771c4e1a297dc37676cd9a5fdec826addfc44.tar.gz
meson-904771c4e1a297dc37676cd9a5fdec826addfc44.tar.bz2
modules/keyval: add type annotations
And use typed_pos_args
Diffstat (limited to 'mesonbuild/modules/keyval.py')
-rw-r--r--mesonbuild/modules/keyval.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/mesonbuild/modules/keyval.py b/mesonbuild/modules/keyval.py
index 559380a..7cebc91 100644
--- a/mesonbuild/modules/keyval.py
+++ b/mesonbuild/modules/keyval.py
@@ -13,23 +13,28 @@
# limitations under the License.
import os
+import typing as T
from . import ExtensionModule
from .. import mesonlib
-from ..interpreterbase import FeatureNew, noKwargs, InvalidCode
-from ..mesonlib import typeslistify
+from ..interpreterbase import FeatureNew, noKwargs, typed_pos_args
+
+if T.TYPE_CHECKING:
+ from ..interpreter import Interpreter
+ from . import ModuleState
class KeyvalModule(ExtensionModule):
@FeatureNew('Keyval Module', '0.55.0')
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
+ def __init__(self, interp: 'Interpreter'):
+ super().__init__(interp)
self.methods.update({
'load': self.load,
})
- def _load_file(self, path_to_config):
- result = dict()
+ @staticmethod
+ def _load_file(path_to_config: str) -> T.Dict[str, str]:
+ result: T.Dict[str, str] = {}
try:
with open(path_to_config, encoding='utf-8') as f:
for line in f:
@@ -48,12 +53,9 @@ class KeyvalModule(ExtensionModule):
return result
@noKwargs
- def load(self, state, args, kwargs):
- sources = typeslistify(args, (str, mesonlib.File))
- if len(sources) != 1:
- raise InvalidCode('load takes only one file input.')
-
- s = sources[0]
+ @typed_pos_args('keyval.laod', (str, mesonlib.File))
+ def load(self, state: 'ModuleState', args: T.Tuple['mesonlib.FileOrString'], kwargs: T.Dict[str, T.Any]) -> T.Dict[str, str]:
+ s = args[0]
is_built = False
if isinstance(s, mesonlib.File):
is_built = is_built or s.is_built
@@ -67,5 +69,5 @@ class KeyvalModule(ExtensionModule):
return self._load_file(s)
-def initialize(*args, **kwargs):
- return KeyvalModule(*args, **kwargs)
+def initialize(interp: 'Interpreter') -> KeyvalModule:
+ return KeyvalModule(interp)