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.
pull/11938/head
Eli Schwartz 1 year ago
parent cff2fb5950
commit 0bb1647fd1
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 3
      mesonbuild/build.py
  2. 4
      mesonbuild/cargo/builder.py
  3. 2
      mesonbuild/cargo/interpreter.py
  4. 2
      mesonbuild/environment.py
  5. 3
      mesonbuild/interpreterbase/interpreterbase.py
  6. 2
      mesonbuild/mintro.py
  7. 2
      mesonbuild/modules/python.py
  8. 6
      mesonbuild/modules/rust.py
  9. 4
      mesonbuild/msubprojects.py

@ -26,7 +26,6 @@ import textwrap
import typing as T import typing as T
from . import coredata from . import coredata
from . import environment
from . import dependencies from . import dependencies
from . import mlog from . import mlog
from . import programs from . import programs
@ -46,6 +45,8 @@ from .interpreterbase import FeatureNew, FeatureDeprecated
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
from typing_extensions import Literal from typing_extensions import Literal
from . import environment
from ._typing import ImmutableListProtocol from ._typing import ImmutableListProtocol
from .backend.backends import Backend from .backend.backends import Backend
from .compilers import Compiler from .compilers import Compiler

@ -8,12 +8,14 @@ build descriptions easier.
""" """
from __future__ import annotations from __future__ import annotations
import builtins
import dataclasses import dataclasses
import typing as T import typing as T
from .. import mparser from .. import mparser
if T.TYPE_CHECKING:
import builtins
def _token(tid: str, filename: str, value: mparser.TV_TokenTypes) -> mparser.Token[mparser.TV_TokenTypes]: 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. """Create a Token object, but with the line numbers stubbed out.

@ -21,7 +21,6 @@ import typing as T
from . import builder from . import builder
from . import version from . import version
from .. import mparser
from .._pathlib import Path from .._pathlib import Path
from ..mesonlib import MesonException, Popen_safe from ..mesonlib import MesonException, Popen_safe
@ -29,6 +28,7 @@ if T.TYPE_CHECKING:
from types import ModuleType from types import ModuleType
from . import manifest from . import manifest
from .. import mparser
from ..environment import Environment from ..environment import Environment
# tomllib is present in python 3.11, before that it is a pypi module called tomli, # tomllib is present in python 3.11, before that it is a pypi module called tomli,

@ -33,7 +33,6 @@ from .envconfig import (
) )
from . import compilers from . import compilers
from .compilers import ( from .compilers import (
Compiler,
is_assembly, is_assembly,
is_header, is_header,
is_library, is_library,
@ -49,6 +48,7 @@ if T.TYPE_CHECKING:
import argparse import argparse
from configparser import ConfigParser from configparser import ConfigParser
from .compilers import Compiler
from .wrap.wrap import Resolver from .wrap.wrap import Resolver
CompilersDict = T.Dict[str, Compiler] CompilersDict = T.Dict[str, Compiler]

@ -22,7 +22,6 @@ from .baseobjects import (
InterpreterObject, InterpreterObject,
MesonInterpreterObject, MesonInterpreterObject,
MutableInterpreterObject, MutableInterpreterObject,
InterpreterObjectTypeVar,
ObjectHolder, ObjectHolder,
IterableObject, IterableObject,
ContextManagerObject, ContextManagerObject,
@ -50,7 +49,7 @@ import typing as T
import textwrap import textwrap
if T.TYPE_CHECKING: 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 from ..interpreter import Interpreter
HolderMapType = T.Dict[ HolderMapType = T.Dict[

@ -429,7 +429,7 @@ def list_deps(coredata: cdata.CoreData, backend: backends.Backend) -> T.List[T.D
d = holder.held_object d = holder.held_object
if isinstance(d, Dependency) and d.found(): if isinstance(d, Dependency) and d.found():
if d.name in result: 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: else:
result[d.name] = _create_result(d, varname) result[d.name] = _create_result(d, varname)

@ -333,7 +333,7 @@ class PythonModule(ExtensionModule):
for i in self.installations.values(): for i in self.installations.values():
if isinstance(i, PythonExternalProgram) and i.run_bytecompile[i.info['version']]: 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 = f'python-{i.info["version"]}-installed.json'
manifest_json = [] manifest_json = []
for name, f in py_files: for name, f in py_files:

@ -18,16 +18,16 @@ import typing as T
from . import ExtensionModule, ModuleReturnValue, ModuleInfo from . import ExtensionModule, ModuleReturnValue, ModuleInfo
from .. import mlog 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 ..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 ..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 ..interpreterbase import ContainerTypeInfo, InterpreterException, KwargInfo, typed_kwargs, typed_pos_args, noPosargs
from ..mesonlib import File from ..mesonlib import File
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
from . import ModuleState from . import ModuleState
from ..build import LibTypes from ..build import IncludeDirs, LibTypes
from ..dependencies import Dependency, ExternalLibrary
from ..interpreter import Interpreter from ..interpreter import Interpreter
from ..interpreter import kwargs as _kwargs from ..interpreter import kwargs as _kwargs
from ..interpreter.interpreter import SourceInputs, SourceOutputs from ..interpreter.interpreter import SourceInputs, SourceOutputs

@ -16,12 +16,14 @@ import zipfile
from . import mlog from . import mlog
from .ast import IntrospectionInterpreter, AstIDGenerator from .ast import IntrospectionInterpreter, AstIDGenerator
from .mesonlib import quiet_git, GitException, Popen_safe, MesonException, windows_proof_rmtree 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) parse_patch_url, update_wrap_file, get_releases)
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
from typing_extensions import Protocol from typing_extensions import Protocol
from .wrap.wrap import PackageDefinition
SubParsers = argparse._SubParsersAction[argparse.ArgumentParser] SubParsers = argparse._SubParsersAction[argparse.ArgumentParser]
class Arguments(Protocol): class Arguments(Protocol):

Loading…
Cancel
Save