diff options
author | Stephen Finucane <sfinucan@redhat.com> | 2022-09-20 16:59:09 +0100 |
---|---|---|
committer | Stephen Finucane <sfinucan@redhat.com> | 2022-10-03 14:23:47 +0100 |
commit | 67217b0e56cae8e88ebb861d3894551e3dedb1b7 (patch) | |
tree | c1fa6e72d65e8b8b49c7ebf172025adf74dc5f0e /cliff/columns.py | |
parent | 9614d30450c642dd176ba00e6b6c2a893d742171 (diff) | |
download | cliff-67217b0e56cae8e88ebb861d3894551e3dedb1b7.tar.gz |
columns: Useful __str__, __repr__ implementation
The default implementations for __str__ and __repr__ are rubbish.
>>> from osc_lib.cli import format_columns
>>> str(format_columns.DictColumn({'foo': 'bar'}))
'<osc_lib.cli.format_columns.DictColumn object at 0x7f6e26771e40>'
>>> repr(format_columns.DictColumn({'foo': 'bar'}))
'<osc_lib.cli.format_columns.DictColumn object at 0x7f6e26b57ac0>'
Make it useful.
>>> from osc_lib.cli import format_columns
>>> str(format_columns.DictColumn({'foo': 'bar'}))
"foo='bar'"
>>> repr(format_columns.DictColumn({'foo': 'bar'}))
"DictColumn({'foo': 'bar'})"
This helps when testing as the reason for mismatches will be more
obvious.
Change-Id: I8b8598875f896cb3dbf417515d377e7758b3b98b
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'cliff/columns.py')
-rw-r--r-- | cliff/columns.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/cliff/columns.py b/cliff/columns.py index b9cac5e..3462176 100644 --- a/cliff/columns.py +++ b/cliff/columns.py @@ -31,6 +31,12 @@ class FormattableColumn(object, metaclass=abc.ABCMeta): self.__class__ == other.__class__ and self._value < other._value ) + def __str__(self): + return self.human_readable() + + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.machine_readable()) + @abc.abstractmethod def human_readable(self): """Return a basic human readable version of the data.""" |