xdoctest.utils.util_mixins module¶
Port of NiceRepr from ubelt.util_mixins
- class xdoctest.utils.util_mixins.NiceRepr[source]¶
Bases:
object
Defines __str__ and __repr__ in terms of __nice__ function Classes that inherit NiceRepr must define __nice__
Example
>>> class Foo(NiceRepr): ... pass >>> class Bar(NiceRepr): ... def __nice__(self): ... return 'info' >>> foo = Foo() >>> bar = Bar() >>> assert str(bar) == '<Bar(info)>' >>> assert repr(bar).startswith('<Bar(info) at ') >>> assert 'object at' in str(foo) >>> assert 'object at' in repr(foo)