aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-02-08 13:53:47 -0800
committerDylan Baker <dylan@pnwbakers.com>2021-05-30 23:32:15 -0700
commit6aef800ba83a4dd469c354900b6e537777d3080c (patch)
tree28815c8b3ee942c7ba2adc15a92fb0526daaba6a /mesonbuild
parent521b92e499b9ce093552f47d4780343f9f725029 (diff)
downloadmeson-6aef800ba83a4dd469c354900b6e537777d3080c.zip
meson-6aef800ba83a4dd469c354900b6e537777d3080c.tar.gz
meson-6aef800ba83a4dd469c354900b6e537777d3080c.tar.bz2
modules/fs: Use typed_kwargs
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/modules/fs.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py
index caa21f7..ab3aae2 100644
--- a/mesonbuild/modules/fs.py
+++ b/mesonbuild/modules/fs.py
@@ -25,12 +25,19 @@ from ..mesonlib import (
MesonException,
path_is_in_root,
)
-from ..interpreterbase import FeatureNew, typed_pos_args, noKwargs, permittedKwargs
+from ..interpreterbase import FeatureNew, KwargInfo, typed_kwargs, typed_pos_args, noKwargs
if T.TYPE_CHECKING:
from . import ModuleState
from ..interpreter import Interpreter
+ from typing_extensions import TypedDict
+
+ class ReadKwArgs(TypedDict):
+ """Keyword Arguments for fs.read."""
+
+ encoding: str
+
class FSModule(ExtensionModule):
@@ -205,9 +212,9 @@ class FSModule(ExtensionModule):
return str(new)
@FeatureNew('fs.read', '0.57.0')
- @permittedKwargs({'encoding'})
@typed_pos_args('fs.read', (str, File))
- def read(self, state: 'ModuleState', args: T.Tuple['FileOrString'], kwargs: T.Dict[str, T.Any]) -> str:
+ @typed_kwargs('fs.read', KwargInfo('encoding', str, default='utf-8'))
+ def read(self, state: 'ModuleState', args: T.Tuple['FileOrString'], kwargs: 'ReadKwArgs') -> str:
"""Read a file from the source tree and return its value as a decoded
string.
@@ -217,10 +224,7 @@ class FSModule(ExtensionModule):
loops)
"""
path = args[0]
- encoding: str = kwargs.get('encoding', 'utf-8')
- if not isinstance(encoding, str):
- raise MesonException('`encoding` parameter must be a string')
-
+ encoding = kwargs['encoding']
src_dir = self.interpreter.environment.source_dir
sub_dir = self.interpreter.subdir
build_dir = self.interpreter.environment.get_build_dir()