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
This commit is contained in:
parent
d7bb0acbe3
commit
d25349e8cf
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue