From 2b4ea20edfcf8ff93be7fbb98dfde5b4ba574b8f Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Wed, 26 Jun 2019 11:07:53 -0400 Subject: [PATCH] bt2: remove __le__() method already provided by @total_ordering The `@total_ordering` decorator already provide all the rich comparison methods because we implement the __lt__() and __eq__() methods. So there is no need to implement any other rich comparison methods. I chose __lt__() arbitrarily but it could have been __le__(), __gt__(), or __ge__(). Documentation on `@total_ordering` [1]: The class must define one of __lt__(), __le__(), __gt__(), or __ge__(). In addition, the class should supply an __eq__() method. [1]: https://docs.python.org/3/library/functools.html#functools.total_ordering Signed-off-by: Francis Deslauriers Change-Id: I4c09ae725acadc59aa17d03063136ffc0dd854c2 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1544 Reviewed-by: Philippe Proulx --- src/bindings/python/bt2/bt2/field.py | 10 ---------- src/bindings/python/bt2/bt2/value.py | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/src/bindings/python/bt2/bt2/field.py b/src/bindings/python/bt2/bt2/field.py index 62dac5ff..99daff5a 100644 --- a/src/bindings/python/bt2/bt2/field.py +++ b/src/bindings/python/bt2/bt2/field.py @@ -101,13 +101,6 @@ class _NumericField(_Field): return self._value < float(other) - def __le__(self, other): - if not isinstance(other, numbers.Number): - raise TypeError('unorderable types: {}() <= {}()'.format(self.__class__.__name__, - other.__class__.__name__)) - - return self._value <= float(other) - def _spec_eq(self, other): if not isinstance(other, numbers.Number): return NotImplemented @@ -382,9 +375,6 @@ class _StringField(_Field): return self._value == other - def __le__(self, other): - return self._value <= self._value_to_str(other) - def __lt__(self, other): return self._value < self._value_to_str(other) diff --git a/src/bindings/python/bt2/bt2/value.py b/src/bindings/python/bt2/bt2/value.py index d8b8332e..22623c22 100644 --- a/src/bindings/python/bt2/bt2/value.py +++ b/src/bindings/python/bt2/bt2/value.py @@ -160,13 +160,6 @@ class _NumericValue(_Value): return self._value < float(other) - def __le__(self, other): - if not isinstance(other, numbers.Number): - raise TypeError('unorderable types: {}() <= {}()'.format(self.__class__.__name__, - other.__class__.__name__)) - - return self._value <= float(other) - def _spec_eq(self, other): pass @@ -475,9 +468,6 @@ class StringValue(collections.abc.Sequence, _Value): except: return - def __le__(self, other): - return self._value <= self._value_to_str(other) - def __lt__(self, other): return self._value < self._value_to_str(other) -- 2.34.1