================
@@ -259,6 +259,44 @@ def which(program):
     return None
 
 
+def _truncate_for_log(text: str, max_characters: int = 32 * 1024) -> str:
+    """
+    Returns ``text`` unchanged if it fits in ``max_characters``, otherwise
+    returns a truncated copy with a trailing note describing how many
+    characters were dropped.
+    """
+    if len(text) <= max_characters:
+        return text
+    dropped = len(text) - max_characters
+    return "{}\n... (output truncated: {} of {} characters omitted)".format(
+        text[:max_characters], dropped, len(text)
+    )
+
+
+def dump_value_obj(val: lldb.SBValue, max_children: int = 10000) -> str:
+    """
+    Returns a string representation of an SBValue suitable for use in
+    diagnostic messages. If the value has more than ``max_children``
+    direct or indirect children, a short placeholder is returned instead
+    of ``str(val)`` to avoid bloating the test log size.
+    """
+    to_visit = [val]
+    total = 0
+    while to_visit:
----------------
DavidSpickett wrote:

https://peps.python.org/pep-0020/

> There should be one-- and preferably only one --obvious way to do it.

Your definition of obvious changes ofc.

I think in this case Black and other formatters will tell you what the 
"Pythonic" way is. Same with `foo == None` versus `foo is None`.

> preferably only one

Looks at string formatting.

https://github.com/llvm/llvm-project/pull/206967
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to