chiark / gitweb /
documentation/python: use an actual ellipsis literal for invalid values.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 26 Sep 2024 19:54:07 +0000 (21:54 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 28 Sep 2024 01:44:29 +0000 (03:44 +0200)
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.

documentation/python.py
documentation/test_python/inspect_type_links/inspect_type_links.second.html
documentation/test_python/inspect_value_formatting/inspect_value_formatting.html
documentation/test_python/inspect_value_formatting/inspect_value_formatting.py

index cc0c6bdc4272ce33500df30dc04c93059c5a063c..3668d889eb5e0a0cbe90dacb33e60641dc636a31 100755 (executable)
@@ -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]
index 2a33768767bd8839bf65f9ee636e9cfc30cf4990..57a60a416ddddf9b2479e3d27b23dd6ef5b5bc8c 100644 (file)
@@ -78,7 +78,7 @@ to None</dd>
             <dt id="type_default_values">
               <span class="m-doc-wrap-bumper">def <a href="#type_default_values" class="m-doc-self">type_default_values</a>(</span><span class="m-doc-wrap">a: <a href="inspect_type_links.second.html#Enum" class="m-doc">Enum</a> = <a href="inspect_type_links.second.html#Enum-SECOND" class="m-doc">Enum.SECOND</a>,
               b: <a href="https://docs.python.org/3/library/typing.html#typing.Tuple" class="m-doc-external">typing.Tuple</a>[<a href="inspect_type_links.second.Foo.html" class="m-doc">Foo</a>] = (&lt;class &#x27;inspect_type_links.second.Foo&#x27;&gt;,),
-              c: <a href="inspect_type_links.second.Foo.html" class="m-doc">Foo</a> = )</span>
+              c: <a href="inspect_type_links.second.Foo.html" class="m-doc">Foo</a> = ...)</span>
             </dt>
             <dd>A function with default values, one enum, one tuple and the third nonrepresentable (yes, the tuple looks ugly)</dd>
             <dt id="type_enum">
index 99e59d7d70c34fdc0a5e478882bafce9dbe517ac..e9f6c3684f206860ef971904274165847c05c6e1 100644 (file)
@@ -29,6 +29,7 @@
             <li>
               Reference
               <ul>
+                <li><a href="#classes">Classes</a></li>
                 <li><a href="#enums">Enums</a></li>
                 <li><a href="#functions">Functions</a></li>
                 <li><a href="#data">Data</a></li>
             </li>
           </ul>
         </nav>
+        <section id="classes">
+          <h2><a href="#classes">Classes</a></h2>
+          <dl class="m-doc">
+            <dt>class <a href="inspect_value_formatting.Foo.html" class="m-doc">Foo</a></dt>
+            <dd></dd>
+          </dl>
+        </section>
         <section id="enums">
           <h2><a href="#enums">Enums</a></h2>
           <dl class="m-doc">
@@ -51,7 +59,8 @@
             <dt id="basics">
               <span class="m-doc-wrap-bumper">def <a href="#basics" class="m-doc-self">basics</a>(</span><span class="m-doc-wrap">string_param = &#x27;string&#x27;,
               tuple_param = (3, 5),
-              float_param = 1.2)</span>
+              float_param = 1.2,
+              unrepresentable_param = ...)</span>
             </dt>
             <dd></dd>
             <dt id="setup_callback">
         <section id="data">
           <h2><a href="#data">Data</a></h2>
           <dl class="m-doc">
+            <dt id="AN_UNREPRESENTABLE_VALUE">
+              <a href="#AN_UNREPRESENTABLE_VALUE" class="m-doc-self">AN_UNREPRESENTABLE_VALUE</a>
+            </dt>
+            <dd></dd>
             <dt id="A_FALSE_VALUE">
               <a href="#A_FALSE_VALUE" class="m-doc-self">A_FALSE_VALUE</a> = False
             </dt>
@@ -80,7 +93,7 @@
             </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> = 
+              <a href="#LARGE_VALUE_WILL_BE_AN_ELLIPSIS" class="m-doc-self">LARGE_VALUE_WILL_BE_AN_ELLIPSIS</a> = ...
             </dt>
             <dd></dd>
           </dl>
index d2b807d87987746712b9d7535b3041e884bf6c08..d4ccdb2684a5f5e83254c4ce52c9c10c225a8379 100644 (file)
@@ -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