merge various TYPE_CHECKING blocks into one

A bunch of files have several T.TYPE_CHECKING blocks that each do some
things which could just as well be done once, with a single `if`
statement. Make them do so.
pull/10072/head
Eli Schwartz 3 years ago
parent d072ebc955
commit 187dc656f4
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 4
      mesonbuild/coredata.py
  2. 8
      mesonbuild/dependencies/detect.py
  3. 4
      mesonbuild/environment.py
  4. 14
      mesonbuild/interpreterbase/baseobjects.py
  5. 22
      mesonbuild/interpreterbase/decorators.py
  6. 65
      mesonbuild/modules/python.py

@ -35,6 +35,7 @@ import typing as T
if T.TYPE_CHECKING:
from . import dependencies
from .compilers.compilers import Compiler, CompileResult
from .dependencies.detect import TV_DepID
from .environment import Environment
from .mesonlib import OptionOverrideProxy, FileOrString
from .cmake.traceparser import CMakeCacheEntry
@ -282,9 +283,6 @@ class UserFeatureOption(UserComboOption):
def is_auto(self) -> bool:
return self.value == 'auto'
if T.TYPE_CHECKING:
from .dependencies.detect import TV_DepID
class DependencyCacheType(enum.Enum):

@ -27,6 +27,9 @@ if T.TYPE_CHECKING:
from ..environment import Environment
from .factory import DependencyFactory, WrappedFactoryFunc, DependencyGenerator
TV_DepIDEntry = T.Union[str, bool, int, T.Tuple[str, ...]]
TV_DepID = T.Tuple[T.Tuple[str, TV_DepIDEntry], ...]
# These must be defined in this file to avoid cyclical references.
packages: T.Dict[
str,
@ -34,11 +37,6 @@ packages: T.Dict[
] = {}
_packages_accept_language: T.Set[str] = set()
if T.TYPE_CHECKING:
TV_DepIDEntry = T.Union[str, bool, int, T.Tuple[str, ...]]
TV_DepID = T.Tuple[T.Tuple[str, TV_DepIDEntry], ...]
def get_dep_identifier(name: str, kwargs: T.Dict[str, T.Any]) -> 'TV_DepID':
identifier: 'TV_DepID' = (('name', name), )
from ..interpreter import permitted_dependency_kwargs

@ -47,6 +47,7 @@ from functools import lru_cache
from mesonbuild import envconfig
if T.TYPE_CHECKING:
import argparse
from configparser import ConfigParser
from .wrap.wrap import Resolver
@ -55,9 +56,6 @@ build_filename = 'meson.build'
CompilersDict = T.Dict[str, Compiler]
if T.TYPE_CHECKING:
import argparse
def _get_env_var(for_machine: MachineChoice, is_cross: bool, var_name: str) -> T.Optional[str]:
"""

@ -23,9 +23,16 @@ import typing as T
from abc import ABCMeta
if T.TYPE_CHECKING:
from typing_extensions import Protocol
# Object holders need the actual interpreter
from ..interpreter import Interpreter
__T = T.TypeVar('__T', bound=TYPE_var, contravariant=True)
class OperatorCall(Protocol[__T]):
def __call__(self, other: __T) -> TYPE_var: ...
TV_fw_var = T.Union[str, int, bool, list, dict, 'InterpreterObject']
TV_fw_args = T.List[T.Union[mparser.BaseNode, TV_fw_var]]
TV_fw_kwargs = T.Dict[str, T.Union[mparser.BaseNode, TV_fw_var]]
@ -41,13 +48,6 @@ TYPE_key_resolver = T.Callable[[mparser.BaseNode], str]
SubProject = T.NewType('SubProject', str)
if T.TYPE_CHECKING:
from typing_extensions import Protocol
__T = T.TypeVar('__T', bound=TYPE_var, contravariant=True)
class OperatorCall(Protocol[__T]):
def __call__(self, other: __T) -> TYPE_var: ...
class InterpreterObject:
def __init__(self, *, subproject: T.Optional['SubProject'] = None) -> None:
self.methods: T.Dict[

@ -25,10 +25,21 @@ import abc
import itertools
import copy
import typing as T
if T.TYPE_CHECKING:
from typing_extensions import Protocol
from .. import mparser
from .baseobjects import InterpreterObject
from .interpreterbase import SubProject
_TV_IntegerObject = T.TypeVar('_TV_IntegerObject', bound=InterpreterObject, contravariant=True)
_TV_ARG1 = T.TypeVar('_TV_ARG1', bound=TYPE_var, contravariant=True)
class FN_Operator(Protocol[_TV_IntegerObject, _TV_ARG1]):
def __call__(s, self: _TV_IntegerObject, other: _TV_ARG1) -> TYPE_var: ...
_TV_FN_Operator = T.TypeVar('_TV_FN_Operator', bound=FN_Operator)
def get_callee_args(wrapped_args: T.Sequence[T.Any]) -> T.Tuple['mparser.BaseNode', T.List['TYPE_var'], 'TYPE_kwargs', 'SubProject']:
# First argument could be InterpreterBase, InterpreterObject or ModuleObject.
# In the case of a ModuleObject it is the 2nd argument (ModuleState) that
@ -116,17 +127,6 @@ class permittedKwargs:
return f(*wrapped_args, **wrapped_kwargs)
return T.cast(TV_func, wrapped)
if T.TYPE_CHECKING:
from .baseobjects import InterpreterObject
from typing_extensions import Protocol
_TV_IntegerObject = T.TypeVar('_TV_IntegerObject', bound=InterpreterObject, contravariant=True)
_TV_ARG1 = T.TypeVar('_TV_ARG1', bound=TYPE_var, contravariant=True)
class FN_Operator(Protocol[_TV_IntegerObject, _TV_ARG1]):
def __call__(s, self: _TV_IntegerObject, other: _TV_ARG1) -> TYPE_var: ...
_TV_FN_Operator = T.TypeVar('_TV_FN_Operator', bound=FN_Operator)
def typed_operator(operator: MesonOperator,
types: T.Union[T.Type, T.Tuple[T.Type, ...]]) -> T.Callable[['_TV_FN_Operator'], '_TV_FN_Operator']:
"""Decorator that does type checking for operator calls.

@ -38,28 +38,52 @@ from ..mesonlib import MachineChoice
from ..programs import ExternalProgram, NonExistingExternalProgram
if T.TYPE_CHECKING:
from typing_extensions import TypedDict
from . import ModuleState
from ..build import SharedModule, Data
from ..dependencies import ExternalDependency, Dependency
from ..dependencies.factory import DependencyGenerator
from ..environment import Environment
from ..interpreter import Interpreter
from ..interpreter.kwargs import ExtractRequired
from ..interpreterbase.interpreterbase import TYPE_var, TYPE_kwargs
from ..backends import InstallData
from typing_extensions import TypedDict
class PythonIntrospectionDict(TypedDict):
install_paths: T.Dict[str, str]
is_pypy: bool
is_venv: bool
link_libpython: bool
sysconfig_paths: T.Dict[str, str]
paths: T.Dict[str, str]
platform: str
suffix: str
variables: T.Dict[str, str]
version: str
mod_kwargs = {'subdir'}
mod_kwargs.update(known_shmod_kwargs)
mod_kwargs -= {'name_prefix', 'name_suffix'}
class PyInstallKw(TypedDict):
pure: bool
subdir: str
install_tag: T.Optional[str]
class FindInstallationKw(ExtractRequired):
disabler: bool
modules: T.List[str]
if T.TYPE_CHECKING:
_Base = ExternalDependency
else:
_Base = object
mod_kwargs = {'subdir'}
mod_kwargs.update(known_shmod_kwargs)
mod_kwargs -= {'name_prefix', 'name_suffix'}
class _PythonDependencyBase(_Base):
def __init__(self, python_holder: 'PythonInstallation', embed: bool):
@ -350,20 +374,6 @@ print(json.dumps({
}))
'''
if T.TYPE_CHECKING:
class PythonIntrospectionDict(TypedDict):
install_paths: T.Dict[str, str]
is_pypy: bool
is_venv: bool
link_libpython: bool
sysconfig_paths: T.Dict[str, str]
paths: T.Dict[str, str]
platform: str
suffix: str
variables: T.Dict[str, str]
version: str
class PythonExternalProgram(ExternalProgram):
def __init__(self, name: str, command: T.Optional[T.List[str]] = None,
@ -474,14 +484,6 @@ class PythonExternalProgram(ExternalProgram):
_PURE_KW = KwargInfo('pure', bool, default=True)
_SUBDIR_KW = KwargInfo('subdir', str, default='')
if T.TYPE_CHECKING:
class PyInstallKw(TypedDict):
pure: bool
subdir: str
install_tag: T.Optional[str]
class PythonInstallation(ExternalProgramHolder):
def __init__(self, python: 'PythonExternalProgram', interpreter: 'Interpreter'):
@ -649,15 +651,6 @@ class PythonInstallation(ExternalProgramHolder):
return super().path_method(args, kwargs)
if T.TYPE_CHECKING:
from ..interpreter.kwargs import ExtractRequired
class FindInstallationKw(ExtractRequired):
disabler: bool
modules: T.List[str]
class PythonModule(ExtensionModule):
@FeatureNew('Python Module', '0.46.0')

Loading…
Cancel
Save