mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 18:24:44 +00:00
Move __repr__ to base class
This commit is contained in:
parent
d449f3ed91
commit
28ede280fc
1 changed files with 14 additions and 13 deletions
|
|
@ -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='',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue