From: Vladimír Vondruš Date: Tue, 3 Sep 2019 18:20:01 +0000 (+0200) Subject: documentation/python: use an ellipsis for overly large values. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=0f4bab5031b9ce7663a9eced1ebf969ee3d4dfd6;p=blog.git documentation/python: use an ellipsis for overly large values. --- diff --git a/documentation/python.py b/documentation/python.py index 91366bdb..a672b8ee 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -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 diff --git a/documentation/test_python/inspect_string/inspect_string.html b/documentation/test_python/inspect_string/inspect_string.html index 6eca098a..bfc5bb38 100644 --- a/documentation/test_python/inspect_string/inspect_string.html +++ b/documentation/test_python/inspect_string/inspect_string.html @@ -120,6 +120,10 @@ ENUM_THING = MyEnum.YAY
+
+ LARGE_VALUE_WILL_BE_AN_ELLIPSIS = … +
+
foo
diff --git a/documentation/test_python/inspect_string/inspect_string/__init__.py b/documentation/test_python/inspect_string/inspect_string/__init__.py index 999087f1..5c67e46d 100644 --- a/documentation/test_python/inspect_string/inspect_string/__init__.py +++ b/documentation/test_python/inspect_string/inspect_string/__init__.py @@ -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()