From c0b8e02d9fb1b58551b18e68ae188263dd90eb4c Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 10 Feb 2022 21:39:50 -0500 Subject: FeatureNew: add mypy type annotations for subproject arg Use a derived type when passing `subproject` around, so that mypy knows it's actually a SubProject, not a str. This means that passing anything other than a handle to the interpreter state's subproject attribute becomes a type violation, specifically when the order of the *four* different str arguments is typoed. --- mesonbuild/optinterpreter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mesonbuild/optinterpreter.py') diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py index 6155c2f..46a4445 100644 --- a/mesonbuild/optinterpreter.py +++ b/mesonbuild/optinterpreter.py @@ -22,6 +22,7 @@ from . import mlog from .interpreterbase import FeatureNew, typed_pos_args, typed_kwargs, ContainerTypeInfo, KwargInfo, permittedKwargs if T.TYPE_CHECKING: from .interpreterbase import TYPE_var, TYPE_kwargs + from .interpreterbase import SubProject from typing_extensions import TypedDict FuncOptionArgs = TypedDict('FuncOptionArgs', { 'type': str, @@ -50,7 +51,7 @@ optname_regex = re.compile('[^a-zA-Z0-9_-]') class OptionInterpreter: - def __init__(self, subproject: str) -> None: + def __init__(self, subproject: 'SubProject') -> None: self.options: 'coredata.KeyedOptionDictType' = {} self.subproject = subproject self.option_types = {'string': self.string_parser, -- cgit v1.1