From caa38dad453905c968ecf1c021e2867f7f4a17e3 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 26 Nov 2023 01:03:08 -0500 Subject: [PATCH] fix broken type annotation imports being ignored If an annotation could not be resolved, it's classified as a "missing import" and our configuration ignored it: ``` Skipping analyzing "mesonbuild.backends": module is installed, but missing library stubs or py.typed marker ``` As far as mypy is concerned, this library may or may not exist, but it doesn't have any typing information at all (may need to be installed first). We ignored this because of our docs/ and tools/ thirdparty dependencies, but we really should not. It is trivial to install them, and then enforce that this "just works". By enforcing it, we also make sure typos get caught. --- .github/workflows/lint.yml | 2 +- .mypy.ini | 2 +- docs/refman/loaderyaml.py | 2 +- mesonbuild/compilers/mixins/compcert.py | 2 +- mesonbuild/interpreter/compiler.py | 5 +++-- mesonbuild/mdevenv.py | 5 +++-- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 547a520cc3f9..ddedabf7ab80 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -46,7 +46,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.x' - - run: python -m pip install mypy types-PyYAML + - run: python -m pip install mypy coverage types-PyYAML types-tqdm types-chevron - run: python run_mypy.py --allver env: PYTHONUNBUFFERED: 1 diff --git a/.mypy.ini b/.mypy.ini index 70fdcd9f3732..d00944bb2ec1 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -2,7 +2,7 @@ strict_optional = False show_error_context = False show_column_numbers = True -ignore_missing_imports = True +ignore_missing_imports = False implicit_reexport = False follow_imports = silent diff --git a/docs/refman/loaderyaml.py b/docs/refman/loaderyaml.py index fc06b0d67084..e7ec57a7e08d 100644 --- a/docs/refman/loaderyaml.py +++ b/docs/refman/loaderyaml.py @@ -41,7 +41,7 @@ class Template: class StrictTemplate(Template): def __init__(self) -> None: - from strictyaml import Map, MapPattern, Optional, Str, Seq, Int, Bool, EmptyList, OrValidator + from strictyaml import Map, MapPattern, Optional, Str, Seq, Int, Bool, EmptyList, OrValidator # type: ignore[import-untyped] d_named_object = { 'name': Str(), diff --git a/mesonbuild/compilers/mixins/compcert.py b/mesonbuild/compilers/mixins/compcert.py index ac4d5aaa07d5..a40f635fa65a 100644 --- a/mesonbuild/compilers/mixins/compcert.py +++ b/mesonbuild/compilers/mixins/compcert.py @@ -20,7 +20,7 @@ import typing as T if T.TYPE_CHECKING: - from envconfig import MachineInfo + from ...envconfig import MachineInfo from ...environment import Environment from ...compilers.compilers import Compiler else: diff --git a/mesonbuild/interpreter/compiler.py b/mesonbuild/interpreter/compiler.py index 5528abe7ade5..ad6eb4b89c63 100644 --- a/mesonbuild/interpreter/compiler.py +++ b/mesonbuild/interpreter/compiler.py @@ -30,7 +30,7 @@ from ..compilers import Compiler, RunResult from ..interpreterbase import TYPE_var, TYPE_kwargs from .kwargs import ExtractRequired, ExtractSearchDirs - from .interpreter.interpreter import SourceOutputs + from .interpreter import SourceOutputs from ..mlog import TV_LoggableList from typing_extensions import TypedDict, Literal @@ -856,7 +856,8 @@ def get_argument_syntax_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwa ) def preprocess_method(self, args: T.Tuple[T.List['mesonlib.FileOrString']], kwargs: 'PreprocessKW') -> T.List[build.CustomTargetIndex]: compiler = self.compiler.get_preprocessor() - sources: 'SourceOutputs' = self.interpreter.source_strings_to_files(args[0]) + _sources: T.List[mesonlib.File] = self.interpreter.source_strings_to_files(args[0]) + sources = T.cast('T.List[SourceOutputs]', _sources) if any(isinstance(s, (build.CustomTarget, build.CustomTargetIndex, build.GeneratedList)) for s in sources): FeatureNew.single_use('compiler.preprocess with generated sources', '1.1.0', self.subproject, location=self.current_node) diff --git a/mesonbuild/mdevenv.py b/mesonbuild/mdevenv.py index 9f3d1b973d28..c8d0144c562f 100644 --- a/mesonbuild/mdevenv.py +++ b/mesonbuild/mdevenv.py @@ -5,6 +5,7 @@ import tempfile import shutil import itertools +import typing as T from pathlib import Path from . import build, minstall @@ -12,9 +13,9 @@ get_wine_shortpath, MachineChoice) from . import mlog -import typing as T + if T.TYPE_CHECKING: - from .backends import InstallData + from .backend.backends import InstallData POWERSHELL_EXES = {'pwsh.exe', 'powershell.exe'}