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/build.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mesonbuild/build.py') diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 782f59c..27e6d36 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -49,6 +49,7 @@ if T.TYPE_CHECKING: from ._typing import ImmutableListProtocol, ImmutableSetProtocol from .backend.backends import Backend, ExecutableSerialisation from .interpreter.interpreter import Test, SourceOutputs, Interpreter + from .interpreterbase import SubProject from .mesonlib import FileMode, FileOrString from .modules import ModuleState from .mparser import BaseNode @@ -514,7 +515,7 @@ class Target(HoldableObject): name: str subdir: str - subproject: str + subproject: 'SubProject' build_by_default: bool for_machine: MachineChoice @@ -675,7 +676,7 @@ class BuildTarget(Target): install_dir: T.List[T.Union[str, bool]] - def __init__(self, name: str, subdir: str, subproject: str, for_machine: MachineChoice, + def __init__(self, name: str, subdir: str, subproject: 'SubProject', for_machine: MachineChoice, sources: T.List['SourceOutputs'], objects, environment: environment.Environment, kwargs): super().__init__(name, subdir, subproject, True, for_machine) unity_opt = environment.coredata.get_option(OptionKey('unity')) -- cgit v1.1