move a bunch of imports into TYPE_CHECKING blocks

These are only used for type checking, so don't bother importing them at
runtime.

Generally add future annotations at the same time, to make sure that
existing uses of these imports don't need to be quoted.
pull/10072/head
Eli Schwartz 3 years ago
parent a009eacc65
commit c231c4bd2a
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 4
      mesonbuild/dependencies/pkgconfig.py
  2. 5
      mesonbuild/interpreter/interpreter.py
  3. 3
      mesonbuild/interpreter/primitives/array.py
  4. 3
      mesonbuild/interpreter/primitives/dict.py
  5. 5
      mesonbuild/interpreter/primitives/integer.py
  6. 5
      mesonbuild/interpreter/primitives/string.py
  7. 3
      mesonbuild/interpreter/type_checking.py
  8. 6
      mesonbuild/interpreterbase/decorators.py
  9. 7
      mesonbuild/interpreterbase/disabler.py
  10. 5
      mesonbuild/interpreterbase/interpreterbase.py
  11. 8
      mesonbuild/linkers/detect.py

@ -11,9 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from .base import ExternalDependency, DependencyException, sort_libpaths, DependencyTypeName
from ..mesonlib import MachineChoice, OptionKey, OrderedSet, PerMachine, Popen_safe
from ..mesonlib import OptionKey, OrderedSet, PerMachine, Popen_safe
from ..programs import find_external_program, ExternalProgram
from .. import mlog
from pathlib import PurePath
@ -24,6 +25,7 @@ import typing as T
if T.TYPE_CHECKING:
from ..environment import Environment
from ..mesonlib import MachineChoice
from .._typing import ImmutableListProtocol
class PkgConfigDependency(ExternalDependency):

@ -33,10 +33,9 @@ from ..interpreterbase import InterpreterException, InvalidArguments, InvalidCod
from ..interpreterbase import Disabler, disablerIfNotFound
from ..interpreterbase import FeatureNew, FeatureDeprecated, FeatureNewKwargs, FeatureDeprecatedKwargs
from ..interpreterbase import ObjectHolder
from ..interpreterbase.baseobjects import InterpreterObject, TYPE_var, TYPE_kwargs
from ..modules import ExtensionModule, ModuleObject, MutableModuleObject, NewExtensionModule, NotFoundExtensionModule
from ..cmake import CMakeInterpreter
from ..backend.backends import Backend, ExecutableSerialisation
from ..backend.backends import ExecutableSerialisation
from . import interpreterobjects as OBJ
from . import compiler as compilerOBJ
@ -96,6 +95,8 @@ if T.TYPE_CHECKING:
from typing_extensions import Literal
from . import kwargs
from ..backend.backends import Backend
from ..interpreterbase.baseobjects import InterpreterObject, TYPE_var, TYPE_kwargs
from ..programs import OverrideProgram
# Input source types passed to Targets

@ -1,5 +1,6 @@
# Copyright 2021 The Meson development team
# SPDX-license-identifier: Apache-2.0
from __future__ import annotations
import typing as T
@ -15,7 +16,6 @@ from ...interpreterbase import (
FeatureNew,
TYPE_var,
TYPE_kwargs,
InvalidArguments,
)
@ -24,6 +24,7 @@ from ...mparser import PlusAssignmentNode
if T.TYPE_CHECKING:
# Object holders need the actual interpreter
from ...interpreter import Interpreter
from ...interpreterbase import TYPE_kwargs
class ArrayHolder(ObjectHolder[T.List[TYPE_var]], IterableObject):
def __init__(self, obj: T.List[TYPE_var], interpreter: 'Interpreter') -> None:

@ -1,5 +1,6 @@
# Copyright 2021 The Meson development team
# SPDX-license-identifier: Apache-2.0
from __future__ import annotations
import typing as T
@ -14,7 +15,6 @@ from ...interpreterbase import (
typed_pos_args,
TYPE_var,
TYPE_kwargs,
InvalidArguments,
)
@ -22,6 +22,7 @@ from ...interpreterbase import (
if T.TYPE_CHECKING:
# Object holders need the actual interpreter
from ...interpreter import Interpreter
from ...interpreterbase import TYPE_kwargs
class DictHolder(ObjectHolder[T.Dict[str, TYPE_var]], IterableObject):
def __init__(self, obj: T.Dict[str, TYPE_var], interpreter: 'Interpreter') -> None:

@ -1,5 +1,6 @@
# Copyright 2021 The Meson development team
# SPDX-license-identifier: Apache-2.0
from __future__ import annotations
from ...interpreterbase import (
ObjectHolder,
@ -8,9 +9,6 @@ from ...interpreterbase import (
noKwargs,
noPosargs,
TYPE_var,
TYPE_kwargs,
InvalidArguments
)
@ -19,6 +17,7 @@ import typing as T
if T.TYPE_CHECKING:
# Object holders need the actual interpreter
from ...interpreter import Interpreter
from ...interpreterbase import TYPE_var, TYPE_kwargs
class IntegerHolder(ObjectHolder[int]):
def __init__(self, obj: int, interpreter: 'Interpreter') -> None:

@ -1,5 +1,6 @@
# Copyright 2021 The Meson development team
# SPDX-license-identifier: Apache-2.0
from __future__ import annotations
import re
import os
@ -17,9 +18,6 @@ from ...interpreterbase import (
noPosargs,
typed_pos_args,
TYPE_var,
TYPE_kwargs,
InvalidArguments,
)
@ -27,6 +25,7 @@ from ...interpreterbase import (
if T.TYPE_CHECKING:
# Object holders need the actual interpreter
from ...interpreter import Interpreter
from ...interpreterbase import TYPE_var, TYPE_kwargs
class StringHolder(ObjectHolder[str]):
def __init__(self, obj: str, interpreter: 'Interpreter') -> None:

@ -11,7 +11,6 @@ from .. import compilers
from ..build import (EnvironmentVariables, EnvInitValueType, CustomTarget, BuildTarget,
CustomTargetIndex, ExtractedObjects, GeneratedList, IncludeDirs)
from ..coredata import UserFeatureOption
from ..interpreterbase import TYPE_var
from ..interpreterbase.decorators import KwargInfo, ContainerTypeInfo
from ..mesonlib import File, FileMode, MachineChoice, listify, has_path_sep, OptionKey
from ..programs import ExternalProgram
@ -22,6 +21,8 @@ NoneType: T.Type[None] = type(None)
if T.TYPE_CHECKING:
from typing_extensions import Literal
from ..interpreterbase import TYPE_var
def in_set_validator(choices: T.Set[str]) -> T.Callable[[str], T.Optional[str]]:
"""Check that the choice given was one of the given set."""

@ -11,12 +11,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from .. import mesonlib, mlog
from .baseobjects import TV_func, TYPE_var, TYPE_kwargs
from .disabler import Disabler
from .exceptions import InterpreterException, InvalidArguments
from .operator import MesonOperator
from ._unholder import _unholder
from dataclasses import dataclass
@ -30,8 +29,9 @@ if T.TYPE_CHECKING:
from typing_extensions import Protocol
from .. import mparser
from .baseobjects import InterpreterObject
from .baseobjects import InterpreterObject, TV_func, TYPE_var, TYPE_kwargs
from .interpreterbase import SubProject
from .operator import MesonOperator
_TV_IntegerObject = T.TypeVar('_TV_IntegerObject', bound=InterpreterObject, contravariant=True)
_TV_ARG1 = T.TypeVar('_TV_ARG1', bound=TYPE_var, contravariant=True)

@ -11,10 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from .baseobjects import MesonInterpreterObject, TYPE_var, TYPE_kwargs
import typing as T
from .baseobjects import MesonInterpreterObject
if T.TYPE_CHECKING:
from .baseobjects import TYPE_var, TYPE_kwargs
class Disabler(MesonInterpreterObject):
def method_call(self, method_name: str, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> TYPE_var:
if method_name == 'found':

@ -14,6 +14,7 @@
# This class contains the basic functionality needed to run any interpreter
# or an interpreter-based tool.
from __future__ import annotations
from .. import mparser, mesonlib
from .. import environment
@ -26,10 +27,7 @@ from .baseobjects import (
ObjectHolder,
IterableObject,
SubProject,
TYPE_var,
TYPE_kwargs,
HoldableTypes,
)
@ -54,6 +52,7 @@ import typing as T
import textwrap
if T.TYPE_CHECKING:
from .baseobjects import SubProject, TYPE_kwargs
from ..interpreter import Interpreter
HolderMapType = T.Dict[

@ -12,14 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from ..mesonlib import (
EnvironmentException, MachineChoice, OptionKey,
EnvironmentException, OptionKey,
Popen_safe, search_version
)
from .linkers import (
DynamicLinker,
AppleDynamicLinker,
GnuDynamicLinker,
GnuGoldDynamicLinker,
GnuBFDDynamicLinker,
LLVMDynamicLinker,
@ -36,8 +36,10 @@ import shlex
import typing as T
if T.TYPE_CHECKING:
from .linkers import DynamicLinker, GnuDynamicLinker
from ..environment import Environment
from ..compilers import Compiler
from ..mesonlib import MachineChoice
defaults: T.Dict[str, T.List[str]] = {}
defaults['static_linker'] = ['ar', 'gar']

Loading…
Cancel
Save