chiark / gitweb /
documentation/python: use an ellipsis for overly large values.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 3 Sep 2019 18:20:01 +0000 (20:20 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 3 Sep 2019 18:20:01 +0000 (20:20 +0200)
documentation/python.py
documentation/test_python/inspect_string/inspect_string.html
documentation/test_python/inspect_string/inspect_string/__init__.py

index 91366bdb63f303922fc237f038feec69c5462a00..a672b8eed95e4547a574fd242c39cb629460ccd9 100755 (executable)
@@ -847,8 +847,10 @@ def format_value(state: State, referrer_path: List[str], value: str) -> Optional
     elif state.config['PYBIND11_COMPATIBILITY'] and hasattr(value.__class__, '__members__'):
         return make_name_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, str(value).partition('.')[2]))
     elif '__repr__' in type(value).__dict__:
+        rendered = repr(value)
         # TODO: tuples of non-representable values will still be ugly
-        return html.escape(repr(value))
+        # If the value is too large, return just an ellipsis
+        return html.escape(rendered) if len(rendered) < 128 else '…'
     else:
         return None
 
index 6eca098a98264b60fc04d7416956cfb4c4a772d2..bfc5bb3884495d7a629494ed92bb45878bf0b3e8 100644 (file)
               <a href="#ENUM_THING" class="m-doc-self">ENUM_THING</a> = <a href="inspect_string.html#MyEnum-YAY" class="m-doc">MyEnum.YAY</a>
             </dt>
             <dd></dd>
+            <dt id="LARGE_VALUE_WILL_BE_AN_ELLIPSIS">
+              <a href="#LARGE_VALUE_WILL_BE_AN_ELLIPSIS" class="m-doc-self">LARGE_VALUE_WILL_BE_AN_ELLIPSIS</a> = …
+            </dt>
+            <dd></dd>
             <dt id="foo">
               <a href="#foo" class="m-doc-self">foo</a>
             </dt>
index 999087f19576559432a57d6cd337d1b66b4790a7..5c67e46d6cb01dc6207d5be95ffcbce79d70fc2c 100644 (file)
@@ -169,6 +169,11 @@ A_ZERO_VALUE = 0
 A_FALSE_VALUE = False
 A_NONE_VALUE = None
 
+# This value is too long and should be completely omitted
+LARGE_VALUE_WILL_BE_AN_ELLIPSIS = """Lorem ipsum dolor sit amet, consectetur
+    adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
+    magna aliqua."""
+
 _PRIVATE_CONSTANT = -3
 
 foo = Foo()