typing: get rid of most T.cast

pull/7657/head
Daniel Mensinger 4 years ago
parent 23818fc5a3
commit 47373a2438
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 2
      mesonbuild/arglist.py
  2. 2
      mesonbuild/compilers/compilers.py
  3. 3
      mesonbuild/coredata.py
  4. 7
      mesonbuild/environment.py
  5. 5
      mesonbuild/interpreterbase.py
  6. 14
      mesonbuild/scripts/regen_checker.py
  7. 4
      mesonbuild/scripts/tags.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:
'''

@ -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[:]

@ -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

@ -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):

@ -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))

@ -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)

@ -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

Loading…
Cancel
Save