diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2020-09-01 19:36:21 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2020-09-08 20:15:58 +0200 |
commit | 47373a2438c0fdeedd229b921c9d7e8dc1fc956a (patch) | |
tree | 9488b247f10bb279e0520d028132ce9f106d63c9 /mesonbuild | |
parent | 23818fc5a389c49e2673f79af2c90d9d56b1aaf0 (diff) | |
download | meson-47373a2438c0fdeedd229b921c9d7e8dc1fc956a.zip meson-47373a2438c0fdeedd229b921c9d7e8dc1fc956a.tar.gz meson-47373a2438c0fdeedd229b921c9d7e8dc1fc956a.tar.bz2 |
typing: get rid of most T.cast
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/arglist.py | 2 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 2 | ||||
-rw-r--r-- | mesonbuild/coredata.py | 3 | ||||
-rw-r--r-- | mesonbuild/environment.py | 7 | ||||
-rw-r--r-- | mesonbuild/interpreterbase.py | 5 | ||||
-rw-r--r-- | mesonbuild/scripts/regen_checker.py | 14 | ||||
-rw-r--r-- | mesonbuild/scripts/tags.py | 4 |
7 files changed, 21 insertions, 16 deletions
diff --git a/mesonbuild/arglist.py b/mesonbuild/arglist.py index b7fa749..d884389 100644 --- a/mesonbuild/arglist.py +++ b/mesonbuild/arglist.py @@ -242,7 +242,7 @@ class CompilerArgs(collections.abc.MutableSequence): new = self.copy() else: new = self - return T.cast(T.List[str], self.compiler.unix_args_to_native(new._container)) + return self.compiler.unix_args_to_native(new._container) def append_direct(self, arg: str) -> None: ''' diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 0de59a4..c97bcc6 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -578,7 +578,7 @@ class Compiler(metaclass=abc.ABCMeta): raise EnvironmentException('Language %s does not support function checks.' % self.get_display_language()) @classmethod - def unix_args_to_native(cls, args): + def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]: "Always returns a copy that can be independently mutated" return args[:] diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 4fc4999..7e966a5 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -365,7 +365,7 @@ _V = T.TypeVar('_V') class CoreData: - def __init__(self, options: argparse.Namespace, scratch_dir: str): + def __init__(self, options: argparse.Namespace, scratch_dir: str, meson_command: T.List[str]): self.lang_guids = { 'default': '8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942', 'c': '8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942', @@ -376,6 +376,7 @@ class CoreData: self.test_guid = str(uuid.uuid4()).upper() self.regen_guid = str(uuid.uuid4()).upper() self.install_guid = str(uuid.uuid4()).upper() + self.meson_command = meson_command self.target_guids = {} self.version = version self.builtins = {} # type: OptionDictType diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 5cd6069..31d0e81 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -814,9 +814,8 @@ class Environment: # WARNING: Don't use any values from coredata in __init__. It gets # re-initialized with project options by the interpreter during # build file parsing. - self.coredata = coredata.CoreData(options, self.scratch_dir) - # Used by the regenchecker script, which runs meson - self.coredata.meson_command = mesonlib.meson_command + # meson_command is used by the regenchecker script, which runs meson + self.coredata = coredata.CoreData(options, self.scratch_dir, mesonlib.meson_command) self.first_invocation = True def is_cross_build(self, when_building_for: MachineChoice = MachineChoice.HOST) -> bool: @@ -1038,7 +1037,7 @@ class Environment: :extra_args: Any additional arguments required (such as a source file) """ self.coredata.add_lang_args(comp_class.language, comp_class, for_machine, self) - extra_args = T.cast(T.List[str], extra_args or []) + extra_args = extra_args or [] extra_args += self.coredata.compiler_options[for_machine][comp_class.language]['args'].value if isinstance(comp_class.LINKER_PREFIX, str): diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index f6c9559..1524409 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -879,6 +879,7 @@ The result of this is undefined and will become a hard error in a future Meson r if not isinstance(index, str): raise InterpreterException('Key is not a string') try: + # The cast is required because we don't have recursive types... return T.cast(TYPE_var, iobject[index]) except KeyError: raise InterpreterException('Key %s is not in dict' % index) @@ -1091,7 +1092,7 @@ The result of this is undefined and will become a hard error in a future Meson r raise InvalidCode('Unknown function "%s".' % func_name) @builtinMethodNoKwargs - def array_method_call(self, obj: list, method_name: str, posargs: T.List[TYPE_nvar], kwargs: T.Dict[str, T.Any]) -> TYPE_var: + def array_method_call(self, obj: T.List[TYPE_var], method_name: str, posargs: T.List[TYPE_nvar], kwargs: T.Dict[str, T.Any]) -> TYPE_var: if method_name == 'contains': def check_contains(el: list) -> bool: if len(posargs) != 1: @@ -1127,7 +1128,7 @@ The result of this is undefined and will become a hard error in a future Meson r if isinstance(fallback, mparser.BaseNode): return self.evaluate_statement(fallback) return fallback - return T.cast(TYPE_var, obj[index]) + return obj[index] m = 'Arrays do not have a method called {!r}.' raise InterpreterException(m.format(method_name)) diff --git a/mesonbuild/scripts/regen_checker.py b/mesonbuild/scripts/regen_checker.py index 84f7d77..fa98f59 100644 --- a/mesonbuild/scripts/regen_checker.py +++ b/mesonbuild/scripts/regen_checker.py @@ -15,13 +15,12 @@ import sys, os import pickle, subprocess import typing as T - -if T.TYPE_CHECKING: - from ..backend.vs2010backend import RegenInfo +from ..coredata import CoreData +from ..backend.vs2010backend import RegenInfo # This could also be used for XCode. -def need_regen(regeninfo: 'RegenInfo', regen_timestamp: float) -> bool: +def need_regen(regeninfo: RegenInfo, regen_timestamp: float) -> bool: for i in regeninfo.depfiles: curfile = os.path.join(regeninfo.build_dir, i) curtime = os.stat(curfile).st_mtime @@ -35,7 +34,7 @@ def need_regen(regeninfo: 'RegenInfo', regen_timestamp: float) -> bool: Vs2010Backend.touch_regen_timestamp(regeninfo.build_dir) return False -def regen(regeninfo: 'RegenInfo', meson_command: T.List[str], backend: str) -> None: +def regen(regeninfo: RegenInfo, meson_command: T.List[str], backend: str) -> None: cmd = meson_command + ['--internal', 'regenerate', regeninfo.build_dir, @@ -48,10 +47,13 @@ def run(args: T.List[str]) -> int: dumpfile = os.path.join(private_dir, 'regeninfo.dump') coredata_file = os.path.join(private_dir, 'coredata.dat') with open(dumpfile, 'rb') as f: - regeninfo = T.cast('RegenInfo', pickle.load(f)) + regeninfo = pickle.load(f) + assert isinstance(regeninfo, RegenInfo) with open(coredata_file, 'rb') as f: coredata = pickle.load(f) + assert isinstance(coredata, CoreData) backend = coredata.get_builtin_option('backend') + assert isinstance(backend, str) regen_timestamp = os.stat(dumpfile).st_mtime if need_regen(regeninfo, regen_timestamp): regen(regeninfo, coredata.meson_command, backend) diff --git a/mesonbuild/scripts/tags.py b/mesonbuild/scripts/tags.py index bb85831..9098efb 100644 --- a/mesonbuild/scripts/tags.py +++ b/mesonbuild/scripts/tags.py @@ -48,4 +48,6 @@ def run(args: T.List[str]) -> int: srcdir_name = args[1] os.chdir(srcdir_name) assert tool_name in ['cscope', 'ctags', 'etags'] - return T.cast(int, globals()[tool_name]()) + res = globals()[tool_name]() + assert isinstance(res, int) + return res |