ubelt.util_mixins module

class ubelt.util_mixins.NiceRepr[source]

Bases: object

Defines __str__ and __repr__ in terms of __nice__ function Classes that inherit NiceRepr must define __nice__

Example

>>> import ubelt as ub
>>> class Foo(ub.NiceRepr):
...    pass
>>> class Bar(ub.NiceRepr):
...    def __nice__(self):
...        return 'info'
>>> foo = Foo()
>>> bar = Bar()
>>> assert str(bar) == '<Bar(info)>'
>>> assert repr(bar).startswith('<Bar(info) at ')
>>> import pytest
>>> with pytest.warns(None) as record:
>>>     assert 'object at' in str(foo)
>>>     assert 'object at' in repr(foo)