Move __repr__ to base class

This commit is contained in:
Ram Rachum 2019-05-03 12:20:41 +03:00
parent d449f3ed91
commit 28ede280fc

View file

@ -31,6 +31,20 @@ class _BaseEntry(pysnooper.pycompat.ABC):
def check(self, s):
pass
def __repr__(self):
init_arguments = get_function_arguments(self.__init__,
exclude=('self',))
attributes = {
key: repr(getattr(self, key)) for key in init_arguments
if getattr(self, key) is not None
}
return '%s(%s)' % (
type(self).__name__,
', '.join('{key}={value}'.format(**locals()) for key, value
in attributes.items())
)
class _BaseValueEntry(_BaseEntry):
def __init__(self, prefix=''):
@ -56,19 +70,6 @@ class _BaseValueEntry(_BaseEntry):
return (self._check_preamble(preamble) and
self._check_content(content))
def __repr__(self):
init_arguments = get_function_arguments(self.__init__,
exclude=('self',))
attributes = {
key: repr(getattr(self, key)) for key in init_arguments
if getattr(self, key) is not None
}
return '%s(%s)' % (
type(self).__name__,
', '.join('{key}={value}'.format(**locals()) for key, value
in attributes.items())
)
class VariableEntry(_BaseValueEntry):
def __init__(self, name=None, value=None, stage=None, prefix='',