typing: Fix code review

pull/7657/head
Daniel Mensinger 5 years ago
parent 1743f636fd
commit 4253bf6281
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 8
      mesonbuild/build.py
  2. 10
      mesonbuild/envconfig.py
  3. 31
      mesonbuild/mesonlib.py

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

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

@ -19,7 +19,7 @@ import stat
import time
import platform, subprocess, operator, os, shlex, shutil, re
import collections
from enum import Enum
from enum import IntEnum
from functools import lru_cache, wraps
from itertools import tee, filterfalse
import typing as T
@ -323,32 +323,7 @@ def classify_unity_sources(compilers: T.Iterable['CompilerType'], sources: T.Ite
return compsrclist
class OrderedEnum(Enum):
"""
An Enum which additionally offers homogeneous ordered comparison.
"""
def __ge__(self, other: object) -> bool:
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 NotImplemented
def __gt__(self, other: object) -> bool:
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 NotImplemented
def __le__(self, other: object) -> bool:
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 NotImplemented
def __lt__(self, other: object) -> bool:
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 NotImplemented
class MachineChoice(OrderedEnum):
class MachineChoice(IntEnum):
"""Enum class representing one of the two abstract machine names used in
most places: the build, and host, machines.
@ -1572,7 +1547,7 @@ def path_is_in_root(path: Path, root: Path, resolve: bool = False) -> bool:
return False
return True
class LibType(Enum):
class LibType(IntEnum):
"""Enumeration for library types."""

Loading…
Cancel
Save