diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-08-10 15:28:02 -0700 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-09-30 21:01:38 +0200 |
commit | d25349e8cf67384b961dc35f7764cf6e9f76b00e (patch) | |
tree | d5f2ca75319ea94ab681e3e7911831595a049ab7 | |
parent | d7bb0acbe3fdfb95757387c006d4b675affc2663 (diff) | |
download | meson-d25349e8cf67384b961dc35f7764cf6e9f76b00e.zip meson-d25349e8cf67384b961dc35f7764cf6e9f76b00e.tar.gz meson-d25349e8cf67384b961dc35f7764cf6e9f76b00e.tar.bz2 |
build: Use isinstance(other, Target) instead of hasattr
In the comparison methods of Target. There are several problems with the
old implementation:
1. It's not idiomatic
2. It can match on things that It shouldn't (like a Compiler, which has
a `get_id() -> str` method, but not one that we should compare with
Targets
3. It confuses mypy, which doesn't handle hasattr
-rw-r--r-- | mesonbuild/build.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 9aad7a3..576bb03 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -513,22 +513,22 @@ class Target(HoldableObject): raise RuntimeError(f'Target type is not set for target class "{type(self).__name__}". This is a bug') def __lt__(self, other: object) -> bool: - if not hasattr(other, 'get_id') and not callable(other.get_id): + if not isinstance(other, Target): return NotImplemented return self.get_id() < other.get_id() def __le__(self, other: object) -> bool: - if not hasattr(other, 'get_id') and not callable(other.get_id): + if not isinstance(other, Target): return NotImplemented return self.get_id() <= other.get_id() def __gt__(self, other: object) -> bool: - if not hasattr(other, 'get_id') and not callable(other.get_id): + if not isinstance(other, Target): return NotImplemented return self.get_id() > other.get_id() def __ge__(self, other: object) -> bool: - if not hasattr(other, 'get_id') and not callable(other.get_id): + if not isinstance(other, Target): return NotImplemented return self.get_id() >= other.get_id() |