types.py: Return `NotImplemented` for unsupported `FastEnum` operations
As per https://docs.python.org/3/library/constants.html#NotImplemented:
A special value which should be returned by the binary special
methods (e.g. __eq__(), __lt__(), __add__(), __rsub__(), etc.) to
indicate that the operation is not implemented with respect to the
other type
This fixes crashes with Click 8.3.0.
diff --git a/src/buildstream/types.py b/src/buildstream/types.py
index efb3385..d4d5e3c 100644
--- a/src/buildstream/types.py
+++ b/src/buildstream/types.py
@@ -67,14 +67,14 @@
def __eq__(self, other):
if self.__class__ is not other.__class__:
- raise ValueError("Unexpected comparison between {} and {}".format(self, repr(other)))
+ return NotImplemented
# Enums instances are unique, so creating an instance with the same value as another will just
# send back the other one, hence we can use an identity comparison, which is much faster than '=='
return self is other
def __ne__(self, other):
if self.__class__ is not other.__class__:
- raise ValueError("Unexpected comparison between {} and {}".format(self, repr(other)))
+ return NotImplemented
return self is not other
def __hash__(self):