Annotate naked fundamental Python types

Although mypy wasn't complaining, pyright was.
pull/11976/head
Tristan Partin 1 year ago
parent 921c2370a7
commit d4bcf05c39
  1. 2
      mesonbuild/compilers/asm.py
  2. 2
      mesonbuild/compilers/compilers.py
  3. 22
      mesonbuild/compilers/cpp.py
  4. 15
      mesonbuild/compilers/d.py
  5. 6
      mesonbuild/compilers/fortran.py
  6. 2
      mesonbuild/compilers/mixins/ccrx.py
  7. 4
      mesonbuild/compilers/mixins/clike.py
  8. 4
      mesonbuild/compilers/mixins/elbrus.py
  9. 2
      mesonbuild/compilers/mixins/emscripten.py
  10. 4
      mesonbuild/compilers/mixins/gnu.py
  11. 2
      mesonbuild/compilers/mixins/metrowerks.py
  12. 2
      mesonbuild/compilers/mixins/ti.py
  13. 4
      mesonbuild/compilers/mixins/visualstudio.py
  14. 6
      mesonbuild/coredata.py
  15. 9
      mesonbuild/environment.py
  16. 12
      mesonbuild/linkers/linkers.py
  17. 16
      mesonbuild/utils/universal.py

@ -69,7 +69,7 @@ class NasmCompiler(Compiler):
return ['-o', outputname]
def unix_args_to_native(self, args: T.List[str]) -> T.List[str]:
outargs = []
outargs: T.List[str] = []
for arg in args:
if arg == '-pthread':
continue

@ -537,7 +537,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
if not hasattr(self, 'file_suffixes'):
self.file_suffixes = lang_suffixes[self.language]
if not hasattr(self, 'can_compile_suffixes'):
self.can_compile_suffixes = set(self.file_suffixes)
self.can_compile_suffixes: T.Set[str] = set(self.file_suffixes)
self.default_suffix = self.file_suffixes[0]
self.version = version
self.full_version = full_version

@ -266,7 +266,7 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
if std.value != 'none':
@ -318,7 +318,7 @@ class EmscriptenCPPCompiler(EmscriptenMixin, ClangCPPCompiler):
defines=defines, full_version=full_version)
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
if std.value != 'none':
@ -362,7 +362,7 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
if std.value != 'none':
@ -428,7 +428,7 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
if std.value != 'none':
@ -539,7 +539,7 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler):
# Elbrus C++ compiler does not support RTTI, so don't check for it.
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
if std.value != 'none':
@ -600,7 +600,7 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
if std.value != 'none':
@ -667,7 +667,7 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
eh = options[key.evolve('eh')]
@ -832,7 +832,7 @@ class ArmCPPCompiler(ArmCompiler, CPPCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
if std.value == 'c++11':
@ -892,7 +892,7 @@ class TICPPCompiler(TICompiler, CPPCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
if std.value != 'none':
@ -931,7 +931,7 @@ class MetrowerksCPPCompilerARM(MetrowerksCompiler, CPPCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
std = options[OptionKey('std', machine=self.for_machine, lang=self.language)]
if std.value != 'none':
args.append('-lang')
@ -960,7 +960,7 @@ class MetrowerksCPPCompilerEmbeddedPowerPC(MetrowerksCompiler, CPPCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
std = options[OptionKey('std', machine=self.for_machine, lang=self.language)]
if std.value != 'none':
args.append('-lang ' + std.value)

@ -172,7 +172,7 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
def get_feature_args(self, kwargs: T.Dict[str, T.Any], build_to_src: str) -> T.List[str]:
# TODO: using a TypeDict here would improve this
res = []
res: T.List[str] = []
# get_feature_args can be called multiple times for the same target when there is generated source
# so we have to copy the kwargs (target.d_features) dict before popping from it
kwargs = kwargs.copy()
@ -277,7 +277,7 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
# The way that dmd and ldc pass rpath to gcc is different than we would
# do directly, each argument -rpath and the value to rpath, need to be
# split into two separate arguments both prefaced with the -L=.
args = []
args: T.List[str] = []
(rpath_args, rpath_dirs_to_remove) = super().build_rpath_args(
env, build_dir, from_dir, rpath_paths, build_rpath, install_rpath)
for r in rpath_args:
@ -298,7 +298,7 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
# can understand.
# The flags might have been added by pkg-config files,
# and are therefore out of the user's control.
dcargs = []
dcargs: T.List[str] = []
# whether we hit a linker argument that expect another arg
# see the comment in the "-L" section
link_expect_arg = False
@ -421,7 +421,7 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
@classmethod
def translate_arg_to_windows(cls, arg: str) -> T.List[str]:
args = []
args: T.List[str] = []
if arg.startswith('-Wl,'):
# Translate linker arguments here.
linkargs = arg[arg.index(',') + 1:].split(',')
@ -447,7 +447,7 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
@classmethod
def _translate_arg_to_osx(cls, arg: str) -> T.List[str]:
args = []
args: T.List[str] = []
if arg.startswith('-install_name'):
args.append('-L=' + arg)
return args
@ -500,15 +500,14 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
# LDC and DMD actually do use a linker, but they proxy all of that with
# their own arguments
soargs: T.List[str] = []
if self.linker.id.startswith('ld.'):
soargs = []
for arg in sargs:
a, b = arg.split(',', maxsplit=1)
soargs.append(a)
soargs.append(self.LINKER_PREFIX + b)
return soargs
elif self.linker.id.startswith('ld64'):
soargs = []
for arg in sargs:
if not arg.startswith(self.LINKER_PREFIX):
soargs.append(self.LINKER_PREFIX + arg)
@ -589,7 +588,7 @@ class DCompiler(Compiler):
def get_feature_args(self, kwargs: T.Dict[str, T.Any], build_to_src: str) -> T.List[str]:
# TODO: using a TypeDict here would improve this
res = []
res: T.List[str] = []
# get_feature_args can be called multiple times for the same target when there is generated source
# so we have to copy the kwargs (target.d_features) dict before popping from it
kwargs = kwargs.copy()

@ -170,7 +170,7 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
if std.value != 'none':
@ -311,7 +311,7 @@ class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
stds = {'legacy': 'none', 'f95': 'f95', 'f2003': 'f03', 'f2008': 'f08', 'f2018': 'f18'}
@ -364,7 +364,7 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
key = OptionKey('std', machine=self.for_machine, lang=self.language)
std = options[key]
stds = {'legacy': 'none', 'f95': 'f95', 'f2003': 'f03', 'f2008': 'f08', 'f2018': 'f18'}

@ -110,7 +110,7 @@ class CcrxCompiler(Compiler):
@classmethod
def _unix_args_to_native(cls, args: T.List[str], info: MachineInfo) -> T.List[str]:
result = []
result: T.List[str] = []
for i in args:
if i.startswith('-D'):
i = '-define=' + i[2:]

@ -226,7 +226,7 @@ class CLikeCompiler(Compiler):
# system directories aren't mixed, we only need to check one file for each
# directory and go by that. If we can't check the file for some reason, assume
# the compiler knows what it's doing, and accept the directory anyway.
retval = []
retval: T.List[str] = []
for d in dirs:
files = [f for f in os.listdir(d) if f.endswith('.so') and os.path.isfile(os.path.join(d, f))]
# if no files, accept directory and move on
@ -1216,7 +1216,7 @@ class CLikeCompiler(Compiler):
def _find_framework_real(self, name: str, env: 'Environment', extra_dirs: T.List[str], allow_system: bool) -> T.Optional[T.List[str]]:
code = 'int main(void) { return 0; }'
link_args = []
link_args: T.List[str] = []
for d in extra_dirs:
link_args += ['-F' + d]
# We can pass -Z to disable searching in the system frameworks, but

@ -74,7 +74,7 @@ class ElbrusCompiler(GnuLikeCompiler):
os_env['LC_ALL'] = 'C'
p = subprocess.Popen(self.get_exelist(ccache=False) + ['-xc', '-E', '-v', '-'], env=os_env, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stderr = p.stderr.read().decode('utf-8', errors='replace')
includes = []
includes: T.List[str] = []
for line in stderr.split('\n'):
if line.lstrip().startswith('--sys_include'):
includes.append(re.sub(r'\s*\\$', '', re.sub(r'^\s*--sys_include\s*', '', line)))
@ -91,7 +91,7 @@ class ElbrusCompiler(GnuLikeCompiler):
return 'pch'
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
args: T.List[str] = []
std = options[OptionKey('std', lang=self.language, machine=self.for_machine)]
if std.value != 'none':
args.append('-std=' + std.value)

@ -37,7 +37,7 @@ else:
def wrap_js_includes(args: T.List[str]) -> T.List[str]:
final_args = []
final_args: T.List[str] = []
for i in args:
if i.endswith('.js') and not i.startswith('-'):
final_args += ['--js-library', i]

@ -483,7 +483,7 @@ class GnuLikeCompiler(Compiler, metaclass=abc.ABCMeta):
# pathlib treats empty paths as '.', so filter those out
paths = [p for p in pathstr.split(pathsep) if p]
result = []
result: T.List[str] = []
for p in paths:
# GCC returns paths like this:
# /usr/lib/gcc/x86_64-linux-gnu/8/../../../../x86_64-linux-gnu/lib
@ -590,7 +590,7 @@ class GnuCompiler(GnuLikeCompiler):
return args
def supported_warn_args(self, warn_args_by_version: T.Dict[str, T.List[str]]) -> T.List[str]:
result = []
result: T.List[str] = []
for version, warn_args in warn_args_by_version.items():
if mesonlib.version_compare(self.version, '>=' + version):
result += warn_args

@ -278,7 +278,7 @@ class MetrowerksCompiler(Compiler):
@classmethod
def _unix_args_to_native(cls, args: T.List[str], info: MachineInfo) -> T.List[str]:
result = []
result: T.List[str] = []
for i in args:
if i.startswith('-D'):
i = '-D' + i[2:]

@ -126,7 +126,7 @@ class TICompiler(Compiler):
@classmethod
def _unix_args_to_native(cls, args: T.List[str], info: MachineInfo) -> T.List[str]:
result = []
result: T.List[str] = []
for i in args:
if i.startswith('-D'):
i = '--define=' + i[2:]

@ -277,7 +277,7 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta):
@classmethod
def native_args_to_unix(cls, args: T.List[str]) -> T.List[str]:
result = []
result: T.List[str] = []
for arg in args:
if arg.startswith(('/LIBPATH:', '-LIBPATH:')):
result.append('-L' + arg[9:])
@ -491,7 +491,7 @@ class ClangClCompiler(VisualStudioLikeCompiler):
def get_dependency_compile_args(self, dep: 'Dependency') -> T.List[str]:
if dep.get_include_type() == 'system':
converted = []
converted: T.List[str] = []
for i in dep.get_compile_args():
if i.startswith('-isystem'):
converted += ['/clang:' + i]

@ -164,7 +164,7 @@ class UserIntegerOption(UserOption[int]):
min_value, max_value, default_value = value
self.min_value = min_value
self.max_value = max_value
c = []
c: T.List[str] = []
if min_value is not None:
c.append('>=' + str(min_value))
if max_value is not None:
@ -419,7 +419,7 @@ class DependencyCache:
def items(self) -> T.Iterator[T.Tuple['TV_DepID', T.List['dependencies.Dependency']]]:
for k, v in self.__cache.items():
vs = []
vs: T.List[dependencies.Dependency] = []
for t in v.types:
subkey = self.__calculate_subkey(t)
if subkey in v:
@ -731,7 +731,7 @@ class CoreData:
self.run_check_cache.clear()
def get_nondefault_buildtype_args(self) -> T.List[T.Union[T.Tuple[str, str, str], T.Tuple[str, bool, bool]]]:
result = []
result: T.List[T.Union[T.Tuple[str, str, str], T.Tuple[str, bool, bool]]] = []
value = self.options[OptionKey('buildtype')].value
if value == 'plain':
opt = 'plain'

@ -178,7 +178,7 @@ def get_llvm_tool_names(tool: str) -> T.List[str]:
'-15', # Debian development snapshot
'-devel', # FreeBSD development snapshot
]
names = []
names: T.List[str] = []
for suffix in suffixes:
names.append(tool + suffix)
return names
@ -197,15 +197,16 @@ def detect_scanbuild() -> T.List[str]:
Return: a single-element list of the found scan-build binary ready to be
passed to Popen()
"""
exelist = []
exelist: T.List[str] = []
if 'SCANBUILD' in os.environ:
exelist = split_args(os.environ['SCANBUILD'])
else:
tools = get_llvm_tool_names('scan-build')
for tool in tools:
if shutil.which(tool) is not None:
exelist = [shutil.which(tool)]
which = shutil.which(tool)
if which is not None:
exelist = [which]
break
if exelist:

@ -374,7 +374,7 @@ class DynamicLinker(metaclass=abc.ABCMeta):
return args
elif isinstance(self.prefix_arg, str):
return [self.prefix_arg + arg for arg in args]
ret = []
ret: T.List[str] = []
for arg in args:
ret += self.prefix_arg + [arg]
return ret
@ -670,14 +670,14 @@ class GnuLikeDynamicLinkerMixin:
return ([], set())
if not rpath_paths and not install_rpath and not build_rpath:
return ([], set())
args = []
args: T.List[str] = []
origin_placeholder = '$ORIGIN'
processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir)
# Need to deduplicate rpaths, as macOS's install_name_tool
# is *very* allergic to duplicate -delete_rpath arguments
# when calling depfixer on installation.
all_paths = mesonlib.OrderedSet([os.path.join(origin_placeholder, p) for p in processed_rpaths])
rpath_dirs_to_remove = set()
rpath_dirs_to_remove: T.Set[bytes] = set()
for p in all_paths:
rpath_dirs_to_remove.add(p.encode('utf8'))
# Build_rpath is used as-is (it is usually absolute).
@ -812,7 +812,7 @@ class AppleDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
if not rpath_paths and not install_rpath and not build_rpath:
return ([], set())
args = []
args: T.List[str] = []
# @loader_path is the equivalent of $ORIGIN on macOS
# https://stackoverflow.com/q/26280738
origin_placeholder = '@loader_path'
@ -1152,7 +1152,7 @@ class NAGDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
if not rpath_paths and not install_rpath and not build_rpath:
return ([], set())
args = []
args: T.List[str] = []
origin_placeholder = '$ORIGIN'
processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir)
all_paths = mesonlib.OrderedSet([os.path.join(origin_placeholder, p) for p in processed_rpaths])
@ -1409,7 +1409,7 @@ class SolarisDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
return ([], set())
processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir)
all_paths = mesonlib.OrderedSet([os.path.join('$ORIGIN', p) for p in processed_rpaths])
rpath_dirs_to_remove = set()
rpath_dirs_to_remove: T.Set[bytes] = set()
for p in all_paths:
rpath_dirs_to_remove.add(p.encode('utf8'))
if build_rpath != '':

@ -913,8 +913,8 @@ def version_compare(vstr1: str, vstr2: str) -> bool:
def version_compare_many(vstr1: str, conditions: T.Union[str, T.Iterable[str]]) -> T.Tuple[bool, T.List[str], T.List[str]]:
if isinstance(conditions, str):
conditions = [conditions]
found = []
not_found = []
found: T.List[str] = []
not_found: T.List[str] = []
for req in conditions:
if not version_compare(vstr1, req):
not_found.append(req)
@ -1123,7 +1123,7 @@ if is_windows():
return result
def split_args(cmd: str) -> T.List[str]:
result = []
result: T.List[str] = []
arg = ''
num_backslashes = 0
num_quotes = 0
@ -1210,7 +1210,7 @@ def do_define(regex: T.Pattern[str], line: str, confdata: 'ConfigurationData',
variable_format: Literal['meson', 'cmake', 'cmake@'], subproject: T.Optional[SubProject] = None) -> str:
def get_cmake_define(line: str, confdata: 'ConfigurationData') -> str:
arr = line.split()
define_value = []
define_value: T.List[str] = []
for token in arr[2:]:
try:
(v, desc) = confdata.get(token)
@ -1277,8 +1277,8 @@ def do_conf_str(src: str, data: list, confdata: 'ConfigurationData',
if variable_format != 'meson':
search_token = '#cmakedefine'
result = []
missing_variables = set()
result: T.List[str] = []
missing_variables: T.Set[str] = set()
# Detect when the configuration data is empty and no tokens were found
# during substitution so we can warn the user to use the `copy:` kwarg.
confdata_useless = not confdata.keys()
@ -2017,9 +2017,9 @@ def get_wine_shortpath(winecmd: T.List[str], wine_paths: T.List[str],
return wine_path
# Check paths that can be reduced by making them relative to workdir.
rel_paths = []
rel_paths: T.List[str] = []
if workdir:
abs_paths = []
abs_paths: T.List[str] = []
for p in wine_paths:
try:
rel = Path(p).relative_to(workdir)

Loading…
Cancel
Save