diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2020-09-03 11:42:53 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2020-09-08 20:15:59 +0200 |
commit | 4253bf62814997bd2c985a2a72e86c260338fb4d (patch) | |
tree | 0c6a6b1f52a6fd9d354369064362cc0d2d9942c1 | |
parent | 1743f636fdb67c7569711e8cabd2d7440ba265be (diff) | |
download | meson-4253bf62814997bd2c985a2a72e86c260338fb4d.zip meson-4253bf62814997bd2c985a2a72e86c260338fb4d.tar.gz meson-4253bf62814997bd2c985a2a72e86c260338fb4d.tar.bz2 |
typing: Fix code review
-rw-r--r-- | mesonbuild/build.py | 8 | ||||
-rw-r--r-- | mesonbuild/envconfig.py | 10 | ||||
-rw-r--r-- | mesonbuild/mesonlib.py | 31 |
3 files changed, 12 insertions, 37 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 369ac7b..7db490a 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.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() diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index 836ec06..3c562f3 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -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) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 6cc3c08..f649738 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -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.""" |