typing: fix code review

pull/7657/head
Daniel Mensinger 4 years ago
parent 47373a2438
commit e681235e5f
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 8
      mesonbuild/arglist.py
  2. 2
      mesonbuild/ast/introspection.py
  3. 8
      mesonbuild/build.py
  4. 8
      mesonbuild/dependencies/boost.py
  5. 10
      mesonbuild/envconfig.py
  6. 32
      mesonbuild/mesonlib.py
  7. 3
      mesonbuild/mintro.py
  8. 2
      mesonbuild/mparser.py
  9. 2
      mesonbuild/scripts/depfixer.py
  10. 2
      mesonbuild/wrap/wrap.py
  11. 2
      run_project_tests.py
  12. 6
      tools/boost_names.py

@ -164,7 +164,7 @@ class CompilerArgs(collections.abc.MutableSequence):
def __getitem__(self, index: slice) -> T.MutableSequence[str]: # noqa: F811 def __getitem__(self, index: slice) -> T.MutableSequence[str]: # noqa: F811
pass pass
def __getitem__(self, index): # type: ignore # noqa: F811 def __getitem__(self, index: T.Union[int, slice]) -> T.Union[str, T.MutableSequence[str]]: # noqa: F811
self.flush_pre_post() self.flush_pre_post()
return self._container[index] return self._container[index]
@ -176,9 +176,9 @@ class CompilerArgs(collections.abc.MutableSequence):
def __setitem__(self, index: slice, value: T.Iterable[str]) -> None: # noqa: F811 def __setitem__(self, index: slice, value: T.Iterable[str]) -> None: # noqa: F811
pass pass
def __setitem__(self, index, value) -> None: # type: ignore # noqa: F811 def __setitem__(self, index: T.Union[int, slice], value: T.Union[str, T.Iterable[str]]) -> None: # noqa: F811
self.flush_pre_post() self.flush_pre_post()
self._container[index] = value self._container[index] = value # type: ignore # TODO: fix 'Invalid index type' and 'Incompatible types in assignment' erros
def __delitem__(self, index: T.Union[int, slice]) -> None: def __delitem__(self, index: T.Union[int, slice]) -> None:
self.flush_pre_post() self.flush_pre_post()
@ -314,7 +314,7 @@ class CompilerArgs(collections.abc.MutableSequence):
new += self new += self
return new return new
def __eq__(self, other: T.Any) -> T.Union[bool]: def __eq__(self, other: object) -> T.Union[bool]:
self.flush_pre_post() self.flush_pre_post()
# Only allow equality checks against other CompilerArgs and lists instances # Only allow equality checks against other CompilerArgs and lists instances
if isinstance(other, CompilerArgs): if isinstance(other, CompilerArgs):

@ -296,7 +296,7 @@ class IntrospectionInterpreter(AstInterpreter):
return None return None
def is_subproject(self) -> bool: def is_subproject(self) -> bool:
return str(self.subproject) != '' return self.subproject != ''
def analyze(self) -> None: def analyze(self) -> None:
self.load_root_meson_file() self.load_root_meson_file()

@ -372,22 +372,22 @@ a hard error in the future.'''.format(name))
if not hasattr(self, 'typename'): if not hasattr(self, 'typename'):
raise RuntimeError('Target type is not set for target class "{}". This is a bug'.format(type(self).__name__)) raise RuntimeError('Target type is not set for target class "{}". This is a bug'.format(type(self).__name__))
def __lt__(self, other: T.Any) -> T.Union[bool, type(NotImplemented)]: def __lt__(self, other: object) -> T.Union[bool, type(NotImplemented)]:
if not hasattr(other, 'get_id') and not callable(other.get_id): if not hasattr(other, 'get_id') and not callable(other.get_id):
return NotImplemented return NotImplemented
return self.get_id() < other.get_id() return self.get_id() < other.get_id()
def __le__(self, other: T.Any) -> T.Union[bool, type(NotImplemented)]: def __le__(self, other: object) -> T.Union[bool, type(NotImplemented)]:
if not hasattr(other, 'get_id') and not callable(other.get_id): if not hasattr(other, 'get_id') and not callable(other.get_id):
return NotImplemented return NotImplemented
return self.get_id() <= other.get_id() return self.get_id() <= other.get_id()
def __gt__(self, other: T.Any) -> T.Union[bool, type(NotImplemented)]: def __gt__(self, other: object) -> T.Union[bool, type(NotImplemented)]:
if not hasattr(other, 'get_id') and not callable(other.get_id): if not hasattr(other, 'get_id') and not callable(other.get_id):
return NotImplemented return NotImplemented
return self.get_id() > other.get_id() return self.get_id() > other.get_id()
def __ge__(self, other: T.Any) -> T.Union[bool, type(NotImplemented)]: def __ge__(self, other: object) -> T.Union[bool, type(NotImplemented)]:
if not hasattr(other, 'get_id') and not callable(other.get_id): if not hasattr(other, 'get_id') and not callable(other.get_id):
return NotImplemented return NotImplemented
return self.get_id() >= other.get_id() return self.get_id() >= other.get_id()

@ -95,7 +95,7 @@ class BoostIncludeDir():
def __repr__(self) -> str: def __repr__(self) -> str:
return '<BoostIncludeDir: {} -- {}>'.format(self.version, self.path) return '<BoostIncludeDir: {} -- {}>'.format(self.version, self.path)
def __lt__(self, other: T.Any) -> bool: def __lt__(self, other: object) -> bool:
if isinstance(other, BoostIncludeDir): if isinstance(other, BoostIncludeDir):
return (self.version_int, self.path) < (other.version_int, other.path) return (self.version_int, self.path) < (other.version_int, other.path)
return NotImplemented return NotImplemented
@ -187,7 +187,7 @@ class BoostLibraryFile():
def __repr__(self) -> str: def __repr__(self) -> str:
return '<LIB: {} {:<32} {}>'.format(self.abitag, self.mod_name, self.path) return '<LIB: {} {:<32} {}>'.format(self.abitag, self.mod_name, self.path)
def __lt__(self, other: T.Any) -> bool: def __lt__(self, other: object) -> bool:
if isinstance(other, BoostLibraryFile): if isinstance(other, BoostLibraryFile):
return ( return (
self.mod_name, self.static, self.version_lib, self.arch, self.mod_name, self.static, self.version_lib, self.arch,
@ -204,7 +204,7 @@ class BoostLibraryFile():
) )
return NotImplemented return NotImplemented
def __eq__(self, other: T.Any) -> bool: def __eq__(self, other: object) -> bool:
if isinstance(other, BoostLibraryFile): if isinstance(other, BoostLibraryFile):
return self.name == other.name return self.name == other.name
return NotImplemented return NotImplemented
@ -346,7 +346,7 @@ class BoostDependency(ExternalDependency):
self.debug = buildtype.startswith('debug') self.debug = buildtype.startswith('debug')
self.multithreading = kwargs.get('threading', 'multi') == 'multi' self.multithreading = kwargs.get('threading', 'multi') == 'multi'
self.boost_root = None # type: Path self.boost_root = None # type: T.Optional[Path]
self.explicit_static = 'static' in kwargs self.explicit_static = 'static' in kwargs
# Extract and validate modules # Extract and validate modules

@ -147,7 +147,7 @@ class Properties:
return p return p
return mesonlib.listify(p) return mesonlib.listify(p)
def __eq__(self, other: T.Any) -> 'T.Union[bool, NotImplemented]': def __eq__(self, other: object) -> 'T.Union[bool, NotImplemented]':
if isinstance(other, type(self)): if isinstance(other, type(self)):
return self.properties == other.properties return self.properties == other.properties
return NotImplemented return NotImplemented
@ -172,8 +172,8 @@ class MachineInfo:
self.endian = endian self.endian = endian
self.is_64_bit = cpu_family in CPU_FAMILES_64_BIT # type: bool self.is_64_bit = cpu_family in CPU_FAMILES_64_BIT # type: bool
def __eq__(self, other: T.Any) -> 'T.Union[bool, NotImplemented]': def __eq__(self, other: object) -> 'T.Union[bool, NotImplemented]':
if self.__class__ is not other.__class__: if self.__class__ is not other.__class__ or not isinstance(other, MachineInfo):
return NotImplemented return NotImplemented
return \ return \
self.system == other.system and \ self.system == other.system and \
@ -181,8 +181,8 @@ class MachineInfo:
self.cpu == other.cpu and \ self.cpu == other.cpu and \
self.endian == other.endian self.endian == other.endian
def __ne__(self, other: T.Any) -> 'T.Union[bool, NotImplemented]': def __ne__(self, other: object) -> 'T.Union[bool, NotImplemented]':
if self.__class__ is not other.__class__: if self.__class__ is not other.__class__ or not isinstance(other, MachineInfo):
return NotImplemented return NotImplemented
return not self.__eq__(other) return not self.__eq__(other)

@ -289,7 +289,7 @@ class File:
def split(self, s: str) -> T.List[str]: def split(self, s: str) -> T.List[str]:
return self.fname.split(s) return self.fname.split(s)
def __eq__(self, other: T.Any) -> bool: def __eq__(self, other: object) -> bool:
if not isinstance(other, File): if not isinstance(other, File):
return NotImplemented return NotImplemented
if self.hash != other.hash: if self.hash != other.hash:
@ -327,23 +327,23 @@ class OrderedEnum(Enum):
""" """
An Enum which additionally offers homogeneous ordered comparison. An Enum which additionally offers homogeneous ordered comparison.
""" """
def __ge__(self, other: T.Any) -> bool: def __ge__(self, other: object) -> bool:
if self.__class__ is other.__class__ and isinstance(self.value, int) and isinstance(other.value, int): if self.__class__ is other.__class__ and isinstance(other, OrderedEnum)and isinstance(self.value, int) and isinstance(other.value, int):
return self.value >= other.value return self.value >= other.value
return NotImplemented return NotImplemented
def __gt__(self, other: T.Any) -> bool: def __gt__(self, other: object) -> bool:
if self.__class__ is other.__class__ and isinstance(self.value, int) and isinstance(other.value, int): if self.__class__ is other.__class__ and isinstance(other, OrderedEnum)and isinstance(self.value, int) and isinstance(other.value, int):
return self.value > other.value return self.value > other.value
return NotImplemented return NotImplemented
def __le__(self, other: T.Any) -> bool: def __le__(self, other: object) -> bool:
if self.__class__ is other.__class__ and isinstance(self.value, int) and isinstance(other.value, int): if self.__class__ is other.__class__ and isinstance(other, OrderedEnum)and isinstance(self.value, int) and isinstance(other.value, int):
return self.value <= other.value return self.value <= other.value
return NotImplemented return NotImplemented
def __lt__(self, other: T.Any) -> bool: def __lt__(self, other: object) -> bool:
if self.__class__ is other.__class__ and isinstance(self.value, int) and isinstance(other.value, int): if self.__class__ is other.__class__ and isinstance(other, OrderedEnum) and isinstance(self.value, int) and isinstance(other.value, int):
return self.value < other.value return self.value < other.value
return NotImplemented return NotImplemented
@ -609,32 +609,32 @@ class Version:
def __repr__(self) -> str: def __repr__(self) -> str:
return '<Version: {}>'.format(self._s) return '<Version: {}>'.format(self._s)
def __lt__(self, other: T.Any) -> bool: def __lt__(self, other: object) -> bool:
if isinstance(other, Version): if isinstance(other, Version):
return self.__cmp(other, operator.lt) return self.__cmp(other, operator.lt)
return NotImplemented return NotImplemented
def __gt__(self, other: T.Any) -> bool: def __gt__(self, other: object) -> bool:
if isinstance(other, Version): if isinstance(other, Version):
return self.__cmp(other, operator.gt) return self.__cmp(other, operator.gt)
return NotImplemented return NotImplemented
def __le__(self, other: T.Any) -> bool: def __le__(self, other: object) -> bool:
if isinstance(other, Version): if isinstance(other, Version):
return self.__cmp(other, operator.le) return self.__cmp(other, operator.le)
return NotImplemented return NotImplemented
def __ge__(self, other: T.Any) -> bool: def __ge__(self, other: object) -> bool:
if isinstance(other, Version): if isinstance(other, Version):
return self.__cmp(other, operator.ge) return self.__cmp(other, operator.ge)
return NotImplemented return NotImplemented
def __eq__(self, other: T.Any) -> bool: def __eq__(self, other: object) -> bool:
if isinstance(other, Version): if isinstance(other, Version):
return self._v == other._v return self._v == other._v
return NotImplemented return NotImplemented
def __ne__(self, other: T.Any) -> bool: def __ne__(self, other: object) -> bool:
if isinstance(other, Version): if isinstance(other, Version):
return self._v != other._v return self._v != other._v
return NotImplemented return NotImplemented
@ -1115,7 +1115,7 @@ def unholder(item: T.List[_T]) -> T.List[_T]: ...
@T.overload @T.overload
def unholder(item: T.List[T.Union[_T, 'ObjectHolder[_T]']]) -> T.List[_T]: ... def unholder(item: T.List[T.Union[_T, 'ObjectHolder[_T]']]) -> T.List[_T]: ...
def unholder(item): # type: ignore # TODO for some reason mypy throws the "Function is missing a type annotation" error def unholder(item): # type: ignore # TODO fix overload (somehow)
"""Get the held item of an object holder or list of object holders.""" """Get the held item of an object holder or list of object holders."""
if isinstance(item, list): if isinstance(item, list):
return [i.held_object if hasattr(i, 'held_object') else i for i in item] return [i.held_object if hasattr(i, 'held_object') else i for i in item]

@ -30,7 +30,8 @@ from .mparser import BaseNode, FunctionNode, ArrayNode, ArgumentNode, StringNode
from .interpreter import Interpreter from .interpreter import Interpreter
from pathlib import PurePath from pathlib import PurePath
import typing as T import typing as T
import os, argparse import os
import argparse
def get_meson_info_file(info_dir: str) -> str: def get_meson_info_file(info_dir: str) -> str:
return os.path.join(info_dir, 'meson-info.json') return os.path.join(info_dir, 'meson-info.json')

@ -97,7 +97,7 @@ class Token(T.Generic[TV_TokenTypes]):
self.bytespan = bytespan # type: T.Tuple[int, int] self.bytespan = bytespan # type: T.Tuple[int, int]
self.value = value # type: TV_TokenTypes self.value = value # type: TV_TokenTypes
def __eq__(self, other: T.Any) -> bool: def __eq__(self, other: object) -> bool:
if isinstance(other, str): if isinstance(other, str):
return self.tid == other return self.tid == other
elif isinstance(other, Token): elif isinstance(other, Token):

@ -328,7 +328,7 @@ class Elf(DataSizes):
new_rpath = b':'.join(new_rpaths) new_rpath = b':'.join(new_rpaths)
if len(old_rpath) < len(new_rpath): if len(old_rpath) < len(new_rpath):
msg = "New rpath must not be longer than the old one.\n Old: {!r}\n New: {!r}".format(old_rpath, new_rpath) msg = "New rpath must not be longer than the old one.\n Old: {}\n New: {}".format(old_rpath.decode('utf-8'), new_rpath.decode('utf-8'))
sys.exit(msg) sys.exit(msg)
# The linker does read-only string deduplication. If there is a # The linker does read-only string deduplication. If there is a
# string that shares a suffix with the rpath, they might get # string that shares a suffix with the rpath, they might get

@ -107,7 +107,7 @@ class WrapNotFoundException(WrapException):
class PackageDefinition: class PackageDefinition:
def __init__(self, fname: str): def __init__(self, fname: str):
self.filename = fname self.filename = fname
self.type = None # type: str self.type = None # type: T.Optional[str]
self.values = {} # type: T.Dict[str, str] self.values = {} # type: T.Dict[str, str]
self.provided_deps = {} # type: T.Dict[str, T.Optional[str]] self.provided_deps = {} # type: T.Dict[str, T.Optional[str]]
self.provided_programs = [] # type: T.List[str] self.provided_programs = [] # type: T.List[str]

@ -216,7 +216,7 @@ class TestDef:
return '{} ({})'.format(self.path.as_posix(), self.name) return '{} ({})'.format(self.path.as_posix(), self.name)
return self.path.as_posix() return self.path.as_posix()
def __lt__(self, other: T.Any) -> bool: def __lt__(self, other: object) -> bool:
if isinstance(other, TestDef): if isinstance(other, TestDef):
# None is not sortable, so replace it with an empty string # None is not sortable, so replace it with an empty string
s_id = int(self.path.name.split(' ')[0]) s_id = int(self.path.name.split(' ')[0])

@ -48,12 +48,12 @@ class BoostLibrary():
self.single = sorted(set(single)) self.single = sorted(set(single))
self.multi = sorted(set(multi)) self.multi = sorted(set(multi))
def __lt__(self, other: T.Any) -> T.Union[bool, 'NotImplemented']: def __lt__(self, other: object) -> T.Union[bool, 'NotImplemented']:
if isinstance(other, BoostLibrary): if isinstance(other, BoostLibrary):
return self.name < other.name return self.name < other.name
return NotImplemented return NotImplemented
def __eq__(self, other: T.Any) -> T.Union[bool, 'NotImplemented']: def __eq__(self, other: object) -> T.Union[bool, 'NotImplemented']:
if isinstance(other, BoostLibrary): if isinstance(other, BoostLibrary):
return self.name == other.name return self.name == other.name
elif isinstance(other, str): elif isinstance(other, str):
@ -71,7 +71,7 @@ class BoostModule():
self.desc = desc self.desc = desc
self.libs = libs self.libs = libs
def __lt__(self, other: T.Any) -> T.Union[bool, 'NotImplemented']: def __lt__(self, other: object) -> T.Union[bool, 'NotImplemented']:
if isinstance(other, BoostModule): if isinstance(other, BoostModule):
return self.key < other.key return self.key < other.key
return NotImplemented return NotImplemented

Loading…
Cancel
Save