-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Description
the default of a trace does not appear in the string representation.
Could adapt str with
def __str__(self):
"""A human-readable string representation (truncated if it gets too
long).
"""
def format_item(item):
return "{!s}: {!s}".format(*item)
MAX_LENGTH = 20
half = MAX_LENGTH // 2
if len(self) > MAX_LENGTH:
one = ", ".join(format_item(_) for _ in self._d.items()[:half])
two = ", ".join(format_item(_) for _ in self._d.items()[half:-half])
three = ", ".join(format_item(_) for _ in self._d.items()[-half:])
truncate_string = f"<...{len(self) - MAX_LENGTH} items...>"
if len(truncate_string) < len(two):
two = truncate_string
items = ", ".join([one, two, three])
else:
items = ", ".join(format_item(_) for _ in self._d.items())
default = f", default={self.default!r}".format(self.default) if self.default else ""
return f"{type(self).__name__}({{{items}}}{default})"Metadata
Metadata
Assignees
Labels
No labels