diff options
author | John Ericson <git@JohnEricson.me> | 2019-02-25 02:45:20 -0500 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2019-05-02 10:58:23 -0700 |
commit | 4c2617a9c6fd02e3f8831b7de8755380ac4bcb16 (patch) | |
tree | 0214fa8f65cd2b9ef66c88c588401907e868ed9f | |
parent | a15a8b7e246be448e79ba20742e713e39807bd00 (diff) | |
download | meson-4c2617a9c6fd02e3f8831b7de8755380ac4bcb16.zip meson-4c2617a9c6fd02e3f8831b7de8755380ac4bcb16.tar.gz meson-4c2617a9c6fd02e3f8831b7de8755380ac4bcb16.tar.bz2 |
Add some type annotations and fix lints
Some things, like `method[...](...)` or `x: ... = ...` python 3.5
doesn't support, so I made a comment instead with the intention that it
can someday be made into a real annotation.
-rw-r--r-- | mesonbuild/build.py | 4 | ||||
-rw-r--r-- | mesonbuild/compilers/cpp.py | 1 | ||||
-rw-r--r-- | mesonbuild/coredata.py | 2 | ||||
-rw-r--r-- | mesonbuild/dependencies/base.py | 5 | ||||
-rw-r--r-- | mesonbuild/envconfig.py | 4 | ||||
-rw-r--r-- | mesonbuild/environment.py | 15 | ||||
-rw-r--r-- | mesonbuild/mesonlib.py | 8 | ||||
-rw-r--r-- | mesonbuild/mintro.py | 2 |
8 files changed, 20 insertions, 21 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 5248d97..4c8e50b 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -28,7 +28,7 @@ from .mesonlib import ( get_filenames_templates_dict, substitute_values, for_windows, for_darwin, for_cygwin, for_android, has_path_sep ) -from .compilers import is_object, clink_langs, sort_clink, lang_suffixes, get_macos_dylib_install_name +from .compilers import Compiler, is_object, clink_langs, sort_clink, lang_suffixes, get_macos_dylib_install_name from .interpreterbase import FeatureNew pch_kwargs = set(['c_pch', 'cpp_pch']) @@ -450,7 +450,7 @@ class BuildTarget(Target): self.is_unity = unity_opt == 'on' or (unity_opt == 'subprojects' and subproject != '') self.environment = environment self.sources = [] - self.compilers = OrderedDict() + self.compilers = OrderedDict() # type: OrderedDict[str, Compiler] self.objects = [] self.external_deps = [] self.include_dirs = [] diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 7c2253d..2b2c4a0 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -23,7 +23,6 @@ from .c import CCompiler, VisualStudioCCompiler, ClangClCCompiler, IntelClCCompi from .compilers import ( gnu_winlibs, msvc_winlibs, - CompilerType, ClangCompiler, GnuCompiler, ElbrusCompiler, diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 9281019..b836086 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -20,7 +20,7 @@ from pathlib import PurePath from collections import OrderedDict from .mesonlib import ( MesonException, MachineChoice, PerMachine, - default_libdir, default_libexecdir, default_prefix, stringlistify + default_libdir, default_libexecdir, default_prefix ) from .wrap import WrapMode import ast diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 6063fd3..1a60a16 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -14,7 +14,6 @@ # This file contains the detection logic for external dependencies. # Custom logic for several other packages are in separate files. -from typing import Dict, Any import copy import functools import os @@ -26,7 +25,7 @@ import textwrap import platform import itertools import ctypes -from typing import List, Tuple +from typing import Any, Dict, List, Tuple from enum import Enum from pathlib import Path, PurePath @@ -2302,7 +2301,7 @@ class ExtraFrameworkDependency(ExternalDependency): return 'framework' -def get_dep_identifier(name, kwargs, want_cross): +def get_dep_identifier(name, kwargs, want_cross: bool) -> Tuple: identifier = (name, want_cross) for key, value in kwargs.items(): # 'version' is irrelevant for caching; the caller must check version matches diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index f4c371f..977d930 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -255,7 +255,7 @@ class MachineInfo: def libdir_layout_is_win(self) -> bool: return self.is_windows() or self.is_cygwin() -class PerMachineDefaultable(PerMachine[_T]): +class PerMachineDefaultable(PerMachine[typing.Optional[_T]]): """Extends `PerMachine` with the ability to default from `None`s. """ def __init__(self) -> None: @@ -285,7 +285,7 @@ class PerMachineDefaultable(PerMachine[_T]): if self.host == self.build: self.host = None -class MachineInfos(PerMachineDefaultable[typing.Optional[MachineInfo]]): +class MachineInfos(PerMachineDefaultable[MachineInfo]): def matches_build_machine(self, machine: MachineChoice) -> bool: return self.build == self[machine] diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index bf2cce9..462672e 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os, platform, re, sys, shlex, shutil, subprocess +import os, platform, re, sys, shlex, shutil, subprocess, typing from . import coredata from .linkers import ArLinker, ArmarLinker, VisualStudioLinker, DLinker, CcrxLinker @@ -28,6 +28,7 @@ from .envconfig import ( ) from . import compilers from .compilers import ( + Compiler, CompilerType, is_assembly, is_header, @@ -83,6 +84,8 @@ from .compilers import ( build_filename = 'meson.build' +CompilersDict = typing.Dict[str, Compiler] + def detect_gcovr(min_version='3.3', new_rootdir_version='4.2', log=False): gcovr_exe = 'gcovr' try: @@ -150,7 +153,7 @@ def detect_native_windows_arch(): raise EnvironmentException('Unable to detect native OS architecture') return arch -def detect_windows_arch(compilers): +def detect_windows_arch(compilers: CompilersDict) -> str: """ Detecting the 'native' architecture of Windows is not a trivial task. We cannot trust that the architecture that Python is built for is the 'native' @@ -190,7 +193,7 @@ def detect_windows_arch(compilers): return 'x86' return os_arch -def any_compiler_has_define(compilers, define): +def any_compiler_has_define(compilers: CompilersDict, define): for c in compilers.values(): try: if c.has_builtin_define(define): @@ -200,7 +203,7 @@ def any_compiler_has_define(compilers, define): pass return False -def detect_cpu_family(compilers): +def detect_cpu_family(compilers: CompilersDict) -> str: """ Python is inconsistent in its platform module. It returns different values for the same cpu. @@ -262,7 +265,7 @@ def detect_cpu_family(compilers): return trial -def detect_cpu(compilers): +def detect_cpu(compilers: CompilersDict): if mesonlib.is_windows(): trial = detect_windows_arch(compilers) else: @@ -295,7 +298,7 @@ def detect_msys2_arch(): return os.environ['MSYSTEM_CARCH'] return None -def detect_machine_info(compilers = None) -> MachineInfo: +def detect_machine_info(compilers: typing.Optional[CompilersDict] = None) -> MachineInfo: """Detect the machine we're running on If compilers are not provided, we cannot know as much. None out those diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index e389fb1..1e776e4 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -323,22 +323,20 @@ class MachineChoice(OrderedEnum): HOST = 1 TARGET = 2 -_T = typing.TypeVar('_T') - class PerMachine(typing.Generic[_T]): - def __init__(self, build: typing.Optional[_T], host: typing.Optional[_T], target: typing.Optional[_T]): + def __init__(self, build: _T, host: _T, target: _T): self.build = build self.host = host self.target = target - def __getitem__(self, machine: MachineChoice) -> typing.Optional[_T]: + def __getitem__(self, machine: MachineChoice) -> _T: return { MachineChoice.BUILD: self.build, MachineChoice.HOST: self.host, MachineChoice.TARGET: self.target }[machine] - def __setitem__(self, machine: MachineChoice, val: typing.Optional[_T]) -> None: + def __setitem__(self, machine: MachineChoice, val: _T) -> None: key = { MachineChoice.BUILD: 'build', MachineChoice.HOST: 'host', diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index a4a6978..c47fffd 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -27,7 +27,7 @@ from . import mlog from .backend import backends from .mparser import FunctionNode, ArrayNode, ArgumentNode, StringNode from typing import List, Optional -import sys, os +import os import pathlib def get_meson_info_file(info_dir: str): |