aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-07-03 12:41:39 -0400
committerEli Schwartz <eschwartz@archlinux.org>2023-07-19 18:31:37 -0400
commit0bb1647fd15cc112098daf9961b2e01cb4e9cd23 (patch)
treecab2094c676a66e3eae55cd16e3f42ae7031e264
parentcff2fb5950cb37b01df5046cc256826449b3abaa (diff)
downloadmeson-0bb1647fd15cc112098daf9961b2e01cb4e9cd23.zip
meson-0bb1647fd15cc112098daf9961b2e01cb4e9cd23.tar.gz
meson-0bb1647fd15cc112098daf9961b2e01cb4e9cd23.tar.bz2
move various bits of type-checking only code to TYPE_CHECKING blocks
Mostly detected with flake8-type-checking. Also quote T.cast() first arguments, since those are not affected by future annotations.
-rw-r--r--mesonbuild/build.py3
-rw-r--r--mesonbuild/cargo/builder.py4
-rw-r--r--mesonbuild/cargo/interpreter.py2
-rw-r--r--mesonbuild/environment.py2
-rw-r--r--mesonbuild/interpreterbase/interpreterbase.py3
-rw-r--r--mesonbuild/mintro.py2
-rw-r--r--mesonbuild/modules/python.py2
-rw-r--r--mesonbuild/modules/rust.py6
-rwxr-xr-xmesonbuild/msubprojects.py4
9 files changed, 16 insertions, 12 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index d588c9d..6438b83 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -26,7 +26,6 @@ import textwrap
import typing as T
from . import coredata
-from . import environment
from . import dependencies
from . import mlog
from . import programs
@@ -46,6 +45,8 @@ from .interpreterbase import FeatureNew, FeatureDeprecated
if T.TYPE_CHECKING:
from typing_extensions import Literal
+
+ from . import environment
from ._typing import ImmutableListProtocol
from .backend.backends import Backend
from .compilers import Compiler
diff --git a/mesonbuild/cargo/builder.py b/mesonbuild/cargo/builder.py
index 49bc65d..fb086d1 100644
--- a/mesonbuild/cargo/builder.py
+++ b/mesonbuild/cargo/builder.py
@@ -8,12 +8,14 @@ build descriptions easier.
"""
from __future__ import annotations
-import builtins
import dataclasses
import typing as T
from .. import mparser
+if T.TYPE_CHECKING:
+ import builtins
+
def _token(tid: str, filename: str, value: mparser.TV_TokenTypes) -> mparser.Token[mparser.TV_TokenTypes]:
"""Create a Token object, but with the line numbers stubbed out.
diff --git a/mesonbuild/cargo/interpreter.py b/mesonbuild/cargo/interpreter.py
index 59e1a1f..8848a46 100644
--- a/mesonbuild/cargo/interpreter.py
+++ b/mesonbuild/cargo/interpreter.py
@@ -21,7 +21,6 @@ import typing as T
from . import builder
from . import version
-from .. import mparser
from .._pathlib import Path
from ..mesonlib import MesonException, Popen_safe
@@ -29,6 +28,7 @@ if T.TYPE_CHECKING:
from types import ModuleType
from . import manifest
+ from .. import mparser
from ..environment import Environment
# tomllib is present in python 3.11, before that it is a pypi module called tomli,
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index ce7c9f1..3ec7713 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -33,7 +33,6 @@ from .envconfig import (
)
from . import compilers
from .compilers import (
- Compiler,
is_assembly,
is_header,
is_library,
@@ -49,6 +48,7 @@ if T.TYPE_CHECKING:
import argparse
from configparser import ConfigParser
+ from .compilers import Compiler
from .wrap.wrap import Resolver
CompilersDict = T.Dict[str, Compiler]
diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py
index d039f6d..9aff5b9 100644
--- a/mesonbuild/interpreterbase/interpreterbase.py
+++ b/mesonbuild/interpreterbase/interpreterbase.py
@@ -22,7 +22,6 @@ from .baseobjects import (
InterpreterObject,
MesonInterpreterObject,
MutableInterpreterObject,
- InterpreterObjectTypeVar,
ObjectHolder,
IterableObject,
ContextManagerObject,
@@ -50,7 +49,7 @@ import typing as T
import textwrap
if T.TYPE_CHECKING:
- from .baseobjects import SubProject, TYPE_kwargs, TYPE_var
+ from .baseobjects import InterpreterObjectTypeVar, SubProject, TYPE_kwargs, TYPE_var
from ..interpreter import Interpreter
HolderMapType = T.Dict[
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index 1d1e858..063c5cd 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -429,7 +429,7 @@ def list_deps(coredata: cdata.CoreData, backend: backends.Backend) -> T.List[T.D
d = holder.held_object
if isinstance(d, Dependency) and d.found():
if d.name in result:
- T.cast(T.List[str], result[d.name]['meson_variables']).append(varname)
+ T.cast('T.List[str]', result[d.name]['meson_variables']).append(varname)
else:
result[d.name] = _create_result(d, varname)
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 1f05f08..f6c82e0 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -333,7 +333,7 @@ class PythonModule(ExtensionModule):
for i in self.installations.values():
if isinstance(i, PythonExternalProgram) and i.run_bytecompile[i.info['version']]:
- i = T.cast(PythonExternalProgram, i)
+ i = T.cast('PythonExternalProgram', i)
manifest = f'python-{i.info["version"]}-installed.json'
manifest_json = []
for name, f in py_files:
diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py
index 3514412..4f5494a 100644
--- a/mesonbuild/modules/rust.py
+++ b/mesonbuild/modules/rust.py
@@ -18,16 +18,16 @@ import typing as T
from . import ExtensionModule, ModuleReturnValue, ModuleInfo
from .. import mlog
-from ..build import BothLibraries, BuildTarget, CustomTargetIndex, Executable, ExtractedObjects, GeneratedList, IncludeDirs, CustomTarget, InvalidArguments, Jar, StructuredSources
+from ..build import BothLibraries, BuildTarget, CustomTargetIndex, Executable, ExtractedObjects, GeneratedList, CustomTarget, InvalidArguments, Jar, StructuredSources
from ..compilers.compilers import are_asserts_disabled
-from ..dependencies import Dependency, ExternalLibrary
from ..interpreter.type_checking import DEPENDENCIES_KW, LINK_WITH_KW, TEST_KWS, OUTPUT_KW, INCLUDE_DIRECTORIES
from ..interpreterbase import ContainerTypeInfo, InterpreterException, KwargInfo, typed_kwargs, typed_pos_args, noPosargs
from ..mesonlib import File
if T.TYPE_CHECKING:
from . import ModuleState
- from ..build import LibTypes
+ from ..build import IncludeDirs, LibTypes
+ from ..dependencies import Dependency, ExternalLibrary
from ..interpreter import Interpreter
from ..interpreter import kwargs as _kwargs
from ..interpreter.interpreter import SourceInputs, SourceOutputs
diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py
index 3ecfba1..d1b51f0 100755
--- a/mesonbuild/msubprojects.py
+++ b/mesonbuild/msubprojects.py
@@ -16,12 +16,14 @@ import zipfile
from . import mlog
from .ast import IntrospectionInterpreter, AstIDGenerator
from .mesonlib import quiet_git, GitException, Popen_safe, MesonException, windows_proof_rmtree
-from .wrap.wrap import (Resolver, WrapException, ALL_TYPES, PackageDefinition,
+from .wrap.wrap import (Resolver, WrapException, ALL_TYPES,
parse_patch_url, update_wrap_file, get_releases)
if T.TYPE_CHECKING:
from typing_extensions import Protocol
+ from .wrap.wrap import PackageDefinition
+
SubParsers = argparse._SubParsersAction[argparse.ArgumentParser]
class Arguments(Protocol):