From 10fc19ecb46bea3b32ec0775818e43c5c942acff Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 8 Mar 2022 15:10:46 -0800 Subject: [PATCH] modules: add typing to the modtest module --- mesonbuild/modules/modtest.py | 21 ++++++++++++++++----- run_mypy.py | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mesonbuild/modules/modtest.py b/mesonbuild/modules/modtest.py index dd2e2ff8d..e36899f0e 100644 --- a/mesonbuild/modules/modtest.py +++ b/mesonbuild/modules/modtest.py @@ -12,19 +12,30 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations +import typing as T + from . import ExtensionModule -from ..interpreterbase import noKwargs +from ..interpreterbase import noKwargs, noPosargs + +if T.TYPE_CHECKING: + from . import ModuleState + from ..interpreter.interpreter import Interpreter + from ..interpreterbase.baseobjects import TYPE_kwargs, TYPE_var + class TestModule(ExtensionModule): - def __init__(self, interpreter): + def __init__(self, interpreter: Interpreter) -> None: super().__init__(interpreter) self.methods.update({ 'print_hello': self.print_hello, }) @noKwargs - def print_hello(self, state, args, kwargs): + @noPosargs + def print_hello(self, state: ModuleState, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> None: print('Hello from a Meson module') -def initialize(*args, **kwargs): - return TestModule(*args, **kwargs) + +def initialize(interp: Interpreter) -> TestModule: + return TestModule(interp) diff --git a/run_mypy.py b/run_mypy.py index d4fde4ff9..b7af49e83 100755 --- a/run_mypy.py +++ b/run_mypy.py @@ -45,6 +45,7 @@ modules = [ 'mesonbuild/modules/i18n.py', 'mesonbuild/modules/java.py', 'mesonbuild/modules/keyval.py', + 'mesonbuild/modules/modtest.py', 'mesonbuild/modules/qt.py', 'mesonbuild/modules/sourceset.py', 'mesonbuild/modules/unstable_external_project.py',