From: Vladimír Vondruš Date: Thu, 26 Sep 2024 19:54:07 +0000 (+0200) Subject: documentation/python: use an actual ellipsis literal for invalid values. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=e7469b7516f6d58a7f3fde8275fe9b8f60ccd86d;p=blog.git documentation/python: use an actual ellipsis literal for invalid values. When they're either too long or unrepresentable, so it can be used also in actual Python (stub) code, the single-character Unicode thingy cannot. --- diff --git a/documentation/python.py b/documentation/python.py index cc0c6bdc..3668d889 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -1102,7 +1102,7 @@ def format_value(state: State, referrer_path: List[str], value) -> Optional[Tupl rendered = repr(value) # TODO: tuples of non-representable values will still be ugly # If the value is too large, return just an ellipsis - out = rendered if len(rendered) < 128 else '…' + out = rendered if len(rendered) < 128 else '...' return out, out, html.escape(out) else: return None @@ -1725,7 +1725,7 @@ def extract_function_doc(state: State, parent, entry: Empty) -> List[Any]: if i.default is inspect.Signature.empty: param.default, param.default_relative, param.default_link = None, None, None else: - param.default, param.default_relative, param.default_link = format_value(state, entry.path, i.default) or ('…', )*3 + param.default, param.default_relative, param.default_link = format_value(state, entry.path, i.default) or ('...', )*3 out.has_complex_params = True param.kind = str(i.kind) out.params += [param] diff --git a/documentation/test_python/inspect_type_links/inspect_type_links.second.html b/documentation/test_python/inspect_type_links/inspect_type_links.second.html index 2a337687..57a60a41 100644 --- a/documentation/test_python/inspect_type_links/inspect_type_links.second.html +++ b/documentation/test_python/inspect_type_links/inspect_type_links.second.html @@ -78,7 +78,7 @@ to None
def type_default_values(a: Enum = Enum.SECOND, b: typing.Tuple[Foo] = (<class 'inspect_type_links.second.Foo'>,), - c: Foo = …) + c: Foo = ...)
A function with default values, one enum, one tuple and the third nonrepresentable (yes, the tuple looks ugly)
diff --git a/documentation/test_python/inspect_value_formatting/inspect_value_formatting.html b/documentation/test_python/inspect_value_formatting/inspect_value_formatting.html index 99e59d7d..e9f6c368 100644 --- a/documentation/test_python/inspect_value_formatting/inspect_value_formatting.html +++ b/documentation/test_python/inspect_value_formatting/inspect_value_formatting.html @@ -29,6 +29,7 @@
  • Reference +
    +

    Classes

    +
    +
    class Foo
    +
    +
    +

    Enums

    @@ -51,7 +59,8 @@
    def basics(string_param = 'string', tuple_param = (3, 5), - float_param = 1.2) + float_param = 1.2, + unrepresentable_param = ...)
    @@ -63,6 +72,10 @@

    Data

    +
    + AN_UNREPRESENTABLE_VALUE +
    +
    A_FALSE_VALUE = False
    @@ -80,7 +93,7 @@
    - LARGE_VALUE_WILL_BE_AN_ELLIPSIS = … + LARGE_VALUE_WILL_BE_AN_ELLIPSIS = ...
    diff --git a/documentation/test_python/inspect_value_formatting/inspect_value_formatting.py b/documentation/test_python/inspect_value_formatting/inspect_value_formatting.py index d2b807d8..d4ccdb26 100644 --- a/documentation/test_python/inspect_value_formatting/inspect_value_formatting.py +++ b/documentation/test_python/inspect_value_formatting/inspect_value_formatting.py @@ -2,7 +2,10 @@ import enum -def basics(string_param = "string", tuple_param = (3, 5), float_param = 1.2): +class Foo: + ... + +def basics(string_param = "string", tuple_param = (3, 5), float_param = 1.2, unrepresentable_param = Foo()): pass def setup_callback(callback = basics): @@ -22,6 +25,7 @@ ENUM_THING = MyEnum.YAY A_ZERO_VALUE = 0 A_FALSE_VALUE = False A_NONE_VALUE = None +AN_UNREPRESENTABLE_VALUE = Foo() # This value is too long and should be completely omitted LARGE_VALUE_WILL_BE_AN_ELLIPSIS = """Lorem ipsum dolor sit amet, consectetur