diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2019-12-05 08:24:56 -0800 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-12-05 22:15:40 +0200 |
commit | e88b3c802250feceaf5fb2950ce7847e6a91626f (patch) | |
tree | 0cb037a1e4ddd203ce18ecceb0de6255242953a3 | |
parent | c616686d5db66f60b344eeae4623361f8ae790b7 (diff) | |
download | meson-e88b3c802250feceaf5fb2950ce7847e6a91626f.zip meson-e88b3c802250feceaf5fb2950ce7847e6a91626f.tar.gz meson-e88b3c802250feceaf5fb2950ce7847e6a91626f.tar.bz2 |
build: Fix type signature of rich comparison dunders
There are three problems:
1) Dunders like `__lt__` and `__gt__` don't return bool, they return
either a bool or the NotImplemented singleton to signal that they don't
know how to be compared.
2) The don't take type object, the take `typing.Any`
3) They need to return NotImplemented if the comparison is not
implemented, this allows python to try the inverse dunder from the
other object. If that object returns NotImplemented as well a
TypeError is raised.
-rw-r--r-- | mesonbuild/build.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 5fb92e2..645db24 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -355,16 +355,24 @@ a hard error in the future.''' % 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) -> bool: + def __lt__(self, other: typing.Any) -> typing.Union[bool, 'NotImplemented']: + 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) -> bool: + def __le__(self, other: typing.Any) -> typing.Union[bool, 'NotImplemented']: + 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) -> bool: + def __gt__(self, other: typing.Any) -> typing.Union[bool, 'NotImplemented']: + 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) -> bool: + def __ge__(self, other: typing.Any) -> typing.Union[bool, 'NotImplemented']: + if not hasattr(other, 'get_id') and not callable(other.get_id): + return NotImplemented return self.get_id() >= other.get_id() def get_install_dir(self, environment): |