From 997e05fce6cf2267099f3d5f91116ba491495d7e Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 4 Nov 2020 14:38:54 +0000 Subject: columns: Make 'FormattableColumn' comparable Currently, comparing instances of this fails: >>> from cliff.columns import FormattableColumn >>> class Test(FormattableColumn): ... def human_readable(self): ... return str(self._data) ... >>> data = {'x': 'y'} >>> x = Test(data) >>> y = Test(data) >>> x == y False Clearly it should not. Resolve this by implementing a custom comparison. Change-Id: I4b96475ca6a689f4055dc5ea34b82b3867a65555 Signed-off-by: Stephen Finucane Story: #2008320 Task: #41218 --- cliff/columns.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cliff/columns.py b/cliff/columns.py index abf1c4f..3b3c2bc 100644 --- a/cliff/columns.py +++ b/cliff/columns.py @@ -24,10 +24,14 @@ class FormattableColumn(object): def __init__(self, value): self._value = value + def __eq__(self, other): + return ( + self.__class__ == other.__class__ and self._value == other._value + ) + @abc.abstractmethod def human_readable(self): - """Return a basic human readable version of the data. - """ + """Return a basic human readable version of the data.""" def machine_readable(self): """Return a raw data structure using only Python built-in types. @@ -35,6 +39,5 @@ class FormattableColumn(object): It must be possible to serialize the return value directly using a formatter like JSON, and it will be up to the formatter plugin to decide how to make that transformation. - """ return self._value -- cgit v1.2.1