From 2fbe268736264fe462d33ef8d2a78dd3cfa69b43 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 23 Jun 2016 07:44:42 -0400 Subject: A SimpleRepr class to inherit a simple __repr__ implementation. --- coverage/misc.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'coverage/misc.py') diff --git a/coverage/misc.py b/coverage/misc.py index e3723c18..f3763461 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -227,6 +227,16 @@ def _needs_to_implement(that, func_name): ) +class SimpleRepr(object): + """A mixin implementing a simple __repr__.""" + def __repr__(self): + return "<{klass} @{id:x} {attrs}>".format( + klass=self.__class__.__name__, + id=id(self) & 0xFFFFFF, + attrs=" ".join("{}={!r}".format(k, v) for k, v in self.__dict__.items()), + ) + + class CoverageException(Exception): """An exception specific to coverage.py.""" pass -- cgit v1.2.1