From d5352d84cc671ffb4e903c977a7f548357b50bc4 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 21 Nov 2024 10:05:16 +0100 Subject: [PATCH] interpreter, rust: move "args" out of BaseTest rust.doctest() will have to typecheck that to a list of strings, no other argument types are allowed. Extract the field out of BaseTest, placing it in FuncBenchmark and the rust modules's FuncTest. Signed-off-by: Paolo Bonzini --- mesonbuild/interpreter/kwargs.py | 4 +++- mesonbuild/interpreter/type_checking.py | 9 ++++++--- mesonbuild/modules/rust.py | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index ae4866a88ad8..61958f2ee8ed 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -38,7 +38,6 @@ class BaseTest(TypedDict): """Shared base for the Rust module.""" - args: T.List[T.Union[str, File, build.Target, ExternalProgram]] should_fail: bool timeout: int workdir: T.Optional[str] @@ -48,10 +47,13 @@ class BaseTest(TypedDict): suite: T.List[str] +TestArgs = T.Union[str, File, build.Target, ExternalProgram] + class FuncBenchmark(BaseTest): """Keyword Arguments shared between `test` and `benchmark`.""" + args: T.List[TestArgs] protocol: Literal['exitcode', 'tap', 'gtest', 'rust'] diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index ed34be950065..7519945cfbd8 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -484,9 +484,7 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus PRESERVE_PATH_KW: KwargInfo[bool] = KwargInfo('preserve_path', bool, default=False, since='0.63.0') -TEST_KWS: T.List[KwargInfo] = [ - KwargInfo('args', ContainerTypeInfo(list, (str, File, BuildTarget, CustomTarget, CustomTargetIndex, ExternalProgram)), - listify=True, default=[]), +TEST_KWS_NO_ARGS: T.List[KwargInfo] = [ KwargInfo('should_fail', bool, default=False), KwargInfo('timeout', int, default=30), KwargInfo('workdir', (str, NoneType), default=None, @@ -503,6 +501,11 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus KwargInfo('verbose', bool, default=False, since='0.62.0'), ] +TEST_KWS: T.List[KwargInfo] = TEST_KWS_NO_ARGS + [ + KwargInfo('args', ContainerTypeInfo(list, (str, File, BuildTarget, CustomTarget, CustomTargetIndex, ExternalProgram)), + listify=True, default=[]), +] + # Cannot have a default value because we need to check that rust_crate_type and # rust_abi are mutually exclusive. RUST_CRATE_TYPE_KW: KwargInfo[T.Union[str, None]] = KwargInfo( diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py index ceba6470632a..3130b3214066 100644 --- a/mesonbuild/modules/rust.py +++ b/mesonbuild/modules/rust.py @@ -34,8 +34,9 @@ from typing_extensions import TypedDict, Literal - class FuncTest(_kwargs.BaseTest): + class FuncTest(TypedDict, _kwargs.BaseTest): + args: T.List[_kwargs.TestArgs] dependencies: T.List[T.Union[Dependency, ExternalLibrary]] is_parallel: bool link_with: T.List[LibTypes]