Skip to content

Commit

Permalink
elide accepts aribtrary value
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom O'Hara committed Sep 3, 2023
1 parent aba7f23 commit fd0bb8a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mezcla/glue_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,20 @@ def indent_lines(text, indentation=None, max_width=512):

MAX_ELIDED_TEXT_LEN = tpo.getenv_integer("MAX_ELIDED_TEXT_LEN", 128)
#
def elide(text: str, max_len=None):
"""Returns TEXT elided to at most MAX_LEN characters (with '...' used to indicate remainder). Note: intended for tracing long string."""
def elide(value, max_len=None):
"""Returns VALUE converted to text and elided to at most MAX_LEN characters (with '...' used to indicate remainder).
Note: intended for tracing long strings."""
# EX: elide("=" * 80, max_len=8) => "========..."
# EX: elide(None) => ""
# NOTE: Make sure compatible with debug.format_value (TODO3: add equivalent to strict argument)
# TODO2: add support for eliding at word-boundaries
tpo.debug_print("elide(_, _)", 8)
debug.assertion(isinstance(text, (str, type(None))))
## OLD: debug.assertion(isinstance(text, (str, type(None))))
text = value
if text is None:
text = ""
if (not isinstance(text, str)):
text = str(text)
if max_len is None:
max_len = MAX_ELIDED_TEXT_LEN
result = text
Expand Down

0 comments on commit fd0bb8a

Please sign in to comment.