diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2022-02-10 21:39:50 -0500 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2022-02-14 20:40:41 -0500 |
commit | c0b8e02d9fb1b58551b18e68ae188263dd90eb4c (patch) | |
tree | ac67d9907a21c04308b33f9a6889b88dad735de7 /mesonbuild/interpreter | |
parent | bab651a7a03b48ff909a49eabe2dbcef0e821496 (diff) | |
download | meson-c0b8e02d9fb1b58551b18e68ae188263dd90eb4c.zip meson-c0b8e02d9fb1b58551b18e68ae188263dd90eb4c.tar.gz meson-c0b8e02d9fb1b58551b18e68ae188263dd90eb4c.tar.bz2 |
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.
Diffstat (limited to 'mesonbuild/interpreter')
-rw-r--r-- | mesonbuild/interpreter/interpreterobjects.py | 3 | ||||
-rw-r--r-- | mesonbuild/interpreter/primitives/range.py | 5 |
2 files changed, 6 insertions, 2 deletions
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index 6b7cbcd..989877e 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -31,6 +31,7 @@ if T.TYPE_CHECKING: from . import kwargs from .interpreter import Interpreter from ..envconfig import MachineInfo + from ..interpreterbase import SubProject from typing_extensions import TypedDict @@ -40,7 +41,7 @@ if T.TYPE_CHECKING: def extract_required_kwarg(kwargs: 'kwargs.ExtractRequired', - subproject: str, + subproject: 'SubProject', feature_check: T.Optional[FeatureCheckBase] = None, default: bool = True) -> T.Tuple[bool, bool, T.Optional[str]]: val = kwargs.get('required', default) diff --git a/mesonbuild/interpreter/primitives/range.py b/mesonbuild/interpreter/primitives/range.py index 9054278..a35470c 100644 --- a/mesonbuild/interpreter/primitives/range.py +++ b/mesonbuild/interpreter/primitives/range.py @@ -10,8 +10,11 @@ from ...interpreterbase import ( InvalidArguments, ) +if T.TYPE_CHECKING: + from ...interpreterbase import SubProject + class RangeHolder(MesonInterpreterObject, IterableObject): - def __init__(self, start: int, stop: int, step: int, *, subproject: str) -> None: + def __init__(self, start: int, stop: int, step: int, *, subproject: 'SubProject') -> None: super().__init__(subproject=subproject) self.range = range(start, stop, step) self.operators.update({ |