chiark / gitweb /
documentation/python: format overloaded func ID only if it's overloaded.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 10 Sep 2019 17:30:09 +0000 (19:30 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 10 Sep 2019 20:10:14 +0000 (22:10 +0200)
So "pybound" functions without overloads still can have nice IDs and
URLs. This should have been done together with
1cd0bb44b77b4225fc5156e1ea7c1a790fe9f7a8 and
6db6b4c4f8296b0fa1b08ce6edeb942db321f6b4 already, but somehow I didn't
make the connection.

documentation/python.py
documentation/test_python/link_formatting/c.link_formatting.pybind.Foo.html
documentation/test_python/link_formatting/m.link_formatting.pybind.html
documentation/test_python/pybind_name_mapping/pybind_name_mapping.Class.html
documentation/test_python/pybind_name_mapping/pybind_name_mapping.submodule.html
documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html
documentation/test_python/pybind_signatures/pybind_signatures.html
documentation/test_python/pybind_type_links/pybind_type_links.Foo.html
documentation/test_python/pybind_type_links/pybind_type_links.html
documentation/test_python/test_search.py

index 582451b3eddcb4bea98879b5dab98df51bc5bfd5..36cd04f96cc0d9f84a75a16f135a48a4115f359f 100755 (executable)
@@ -1416,9 +1416,12 @@ def extract_function_doc(state: State, parent, entry: Empty) -> List[Any]:
 
                 out.params += [param]
 
-            # Format the anchor. Pybind11 functions are sometimes overloaded,
-            # thus name alone is not enough.
-            out.id = state.config['ID_FORMATTER'](EntryType.OVERLOADED_FUNCTION, entry.path[-1:] + param_types)
+            # Format the anchor, include types only if there's really more than
+            # one overload
+            if entry.type == EntryType.OVERLOADED_FUNCTION:
+                out.id = state.config['ID_FORMATTER'](EntryType.OVERLOADED_FUNCTION, [name] + param_types)
+            else:
+                out.id = state.config['ID_FORMATTER'](EntryType.FUNCTION, [name])
 
             # Call all scope enter hooks for this particular overload
             for hook in state.hooks_pre_scope:
index 77b0a7483ade3316339bda3b49b7013d8fb2f181..6e37feeb64f36f154be841a4988aae51656024ec 100644 (file)
@@ -56,8 +56,8 @@
         <section id="staticmethods">
           <h2><a href="#staticmethods">Static methods</a></h2>
           <dl class="m-doc">
-            <dt id="o-a_function-46f8a">
-              <span class="m-doc-wrap-bumper">def <a href="#o-a_function-46f8a" class="m-doc-self">a_function</a>(</span><span class="m-doc-wrap">arg0: int<span class="m-text m-dim">, /</span>) -&gt; int</span>
+            <dt id="f-a_function">
+              <span class="m-doc-wrap-bumper">def <a href="#f-a_function" class="m-doc-self">a_function</a>(</span><span class="m-doc-wrap">arg0: int<span class="m-text m-dim">, /</span>) -&gt; int</span>
             </dt>
             <dd>A static function that should have the same hash as takes_int()</dd>
           </dl>
         <section id="methods">
           <h2><a href="#methods">Methods</a></h2>
           <dl class="m-doc">
-            <dt id="o-bar-745a3">
-              <span class="m-doc-wrap-bumper">def <a href="#o-bar-745a3" class="m-doc-self">bar</a>(</span><span class="m-doc-wrap">self,
+            <dt id="f-bar">
+              <span class="m-doc-wrap-bumper">def <a href="#f-bar" class="m-doc-self">bar</a>(</span><span class="m-doc-wrap">self,
               arg0: int<span class="m-text m-dim">, /</span>) -&gt; int</span>
             </dt>
             <dd>Should have the same hash as foo() but not as a_function()</dd>
-            <dt id="o-foo-745a3">
-              <span class="m-doc-wrap-bumper">def <a href="#o-foo-745a3" class="m-doc-self">foo</a>(</span><span class="m-doc-wrap">self,
+            <dt id="f-foo">
+              <span class="m-doc-wrap-bumper">def <a href="#f-foo" class="m-doc-self">foo</a>(</span><span class="m-doc-wrap">self,
               arg0: int<span class="m-text m-dim">, /</span>) -&gt; int</span>
             </dt>
             <dd>Should have the same hash as bar() but not as a_function()</dd>
index 7f47d9d294593486a0e31c91d054a92adca525f8..b0152d3e47499adf4700460f7e6625984468a5c2 100644 (file)
@@ -77,8 +77,8 @@
               arg1: <a href="c.link_formatting.pybind.Foo.html#this-is-an-url" class="m-doc">Foo</a><span class="m-text m-dim">, /</span>) -&gt; int</span>
             </dt>
             <dd>Each overload should have a different hash</dd>
-            <dt id="o-takes_int-46f8a">
-              <span class="m-doc-wrap-bumper">def <a href="#o-takes_int-46f8a" class="m-doc-self">takes_int</a>(</span><span class="m-doc-wrap">arg0: int<span class="m-text m-dim">, /</span>) -&gt; int</span>
+            <dt id="f-takes_int">
+              <span class="m-doc-wrap-bumper">def <a href="#f-takes_int" class="m-doc-self">takes_int</a>(</span><span class="m-doc-wrap">arg0: int<span class="m-text m-dim">, /</span>) -&gt; int</span>
             </dt>
             <dd>Should have the same hash as Foo.a_function()</dd>
           </dl>
index 94c16d83b487eb067895dda6e193fac8dd5d52f0..246af4ea7dce889349f12d45ad32836c5a15f7c7 100644 (file)
@@ -37,8 +37,8 @@
         <section id="staticmethods">
           <h2><a href="#staticmethods">Static methods</a></h2>
           <dl class="m-doc">
-            <dt id="a_thing-da39a">
-              <span class="m-doc-wrap-bumper">def <a href="#a_thing-da39a" class="m-doc-self">a_thing</a>(</span><span class="m-doc-wrap">) -&gt; <a href="pybind_name_mapping.Class.html" class="m-doc">Class</a></span>
+            <dt id="a_thing">
+              <span class="m-doc-wrap-bumper">def <a href="#a_thing" class="m-doc-self">a_thing</a>(</span><span class="m-doc-wrap">) -&gt; <a href="pybind_name_mapping.Class.html" class="m-doc">Class</a></span>
             </dt>
             <dd>A method</dd>
           </dl>
index 58683c8ec7d2ae3a34e210a474f8891dd1489df6..a50521e1754958103d4e9ae65947c0ee3e26cd48 100644 (file)
@@ -37,8 +37,8 @@
         <section id="functions">
           <h2><a href="#functions">Functions</a></h2>
           <dl class="m-doc">
-            <dt id="foo-c5914">
-              <span class="m-doc-wrap-bumper">def <a href="#foo-c5914" class="m-doc-self">foo</a>(</span><span class="m-doc-wrap">arg0: <a href="pybind_name_mapping.Class.html" class="m-doc">Class</a>,
+            <dt id="foo">
+              <span class="m-doc-wrap-bumper">def <a href="#foo" class="m-doc-self">foo</a>(</span><span class="m-doc-wrap">arg0: <a href="pybind_name_mapping.Class.html" class="m-doc">Class</a>,
               arg1: int<span class="m-text m-dim">, /</span>) -&gt; int</span>
             </dt>
             <dd>A function</dd>
index 7d1628c640808029f78555be49492510b80ace76..5343d0ce075453541dfc5d329ccf68f2b246b019 100644 (file)
@@ -40,8 +40,8 @@
         <section id="staticmethods">
           <h2><a href="#staticmethods">Static methods</a></h2>
           <dl class="m-doc">
-            <dt id="static_function-8f19c">
-              <span class="m-doc-wrap-bumper">def <a href="#static_function-8f19c" class="m-doc-self">static_function</a>(</span><span class="m-doc-wrap">arg0: int,
+            <dt id="static_function">
+              <span class="m-doc-wrap-bumper">def <a href="#static_function" class="m-doc-self">static_function</a>(</span><span class="m-doc-wrap">arg0: int,
               arg1: float<span class="m-text m-dim">, /</span>) -&gt; <a href="pybind_signatures.MyClass.html" class="m-doc">MyClass</a></span>
             </dt>
             <dd>Static method with positional-only args</dd>
         <section id="methods">
           <h2><a href="#methods">Methods</a></h2>
           <dl class="m-doc">
-            <dt id="another-6eef6">
-              <span class="m-doc-wrap-bumper">def <a href="#another-6eef6" class="m-doc-self">another</a>(</span><span class="m-doc-wrap">self<span class="m-text m-dim">, /</span>) -&gt; int</span>
+            <dt id="another">
+              <span class="m-doc-wrap-bumper">def <a href="#another" class="m-doc-self">another</a>(</span><span class="m-doc-wrap">self<span class="m-text m-dim">, /</span>) -&gt; int</span>
             </dt>
             <dd>Instance method with no args, &#x27;self&#x27; is thus position-only</dd>
-            <dt id="instance_function-a8577">
-              <span class="m-doc-wrap-bumper">def <a href="#instance_function-a8577" class="m-doc-self">instance_function</a>(</span><span class="m-doc-wrap">self,
+            <dt id="instance_function">
+              <span class="m-doc-wrap-bumper">def <a href="#instance_function" class="m-doc-self">instance_function</a>(</span><span class="m-doc-wrap">self,
               arg0: int,
               arg1: str<span class="m-text m-dim">, /</span>) -&gt; typing.Tuple[float, int]</span>
             </dt>
             <dd>Instance method with positional-only args</dd>
-            <dt id="instance_function_kwargs-a8577">
-              <span class="m-doc-wrap-bumper">def <a href="#instance_function_kwargs-a8577" class="m-doc-self">instance_function_kwargs</a>(</span><span class="m-doc-wrap">self,
+            <dt id="instance_function_kwargs">
+              <span class="m-doc-wrap-bumper">def <a href="#instance_function_kwargs" class="m-doc-self">instance_function_kwargs</a>(</span><span class="m-doc-wrap">self,
               hey: int,
               what: str = &#x27;&lt;eh?&gt;&#x27;) -&gt; typing.Tuple[float, int]</span>
             </dt>
@@ -71,8 +71,8 @@
         <section id="dunder-methods">
           <h2><a href="#dunder-methods">Special methods</a></h2>
           <dl class="m-doc">
-            <dt id="__init__-6eef6">
-              <span class="m-doc-wrap-bumper">def <a href="#__init__-6eef6" class="m-doc-self">__init__</a>(</span><span class="m-doc-wrap">self<span class="m-text m-dim">, /</span>) -&gt; None</span>
+            <dt id="__init__">
+              <span class="m-doc-wrap-bumper">def <a href="#__init__" class="m-doc-self">__init__</a>(</span><span class="m-doc-wrap">self<span class="m-text m-dim">, /</span>) -&gt; None</span>
             </dt>
             <dd>Constructor</dd>
           </dl>
index 2ff53e0701d92ef425612fb11bc3a0f8dbd6840a..832b92ed0639d5df55d39e593129abb140c69df4 100644 (file)
         <section id="functions">
           <h2><a href="#functions">Functions</a></h2>
           <dl class="m-doc">
-            <dt id="crazy_signature-6eef6">
-              <span class="m-doc-wrap-bumper">def <a href="#crazy_signature-6eef6" class="m-doc-self">crazy_signature</a>(</span><span class="m-doc-wrap">…)</span>
+            <dt id="crazy_signature">
+              <span class="m-doc-wrap-bumper">def <a href="#crazy_signature" class="m-doc-self">crazy_signature</a>(</span><span class="m-doc-wrap">…)</span>
             </dt>
             <dd>Function that failed to get parsed</dd>
-            <dt id="duck-9024d">
-              <span class="m-doc-wrap-bumper">def <a href="#duck-9024d" class="m-doc-self">duck</a>(</span><span class="m-doc-wrap">*args, **kwargs) -&gt; None</span>
+            <dt id="duck">
+              <span class="m-doc-wrap-bumper">def <a href="#duck" class="m-doc-self">duck</a>(</span><span class="m-doc-wrap">*args, **kwargs) -&gt; None</span>
             </dt>
             <dd>A function taking args/kwargs directly</dd>
-            <dt id="escape_docstring-46f8a">
-              <span class="m-doc-wrap-bumper">def <a href="#escape_docstring-46f8a" class="m-doc-self">escape_docstring</a>(</span><span class="m-doc-wrap">arg0: int<span class="m-text m-dim">, /</span>) -&gt; None</span>
+            <dt id="escape_docstring">
+              <span class="m-doc-wrap-bumper">def <a href="#escape_docstring" class="m-doc-self">escape_docstring</a>(</span><span class="m-doc-wrap">arg0: int<span class="m-text m-dim">, /</span>) -&gt; None</span>
             </dt>
             <dd>A docstring that &lt;em&gt;should&lt;/em&gt; be escaped</dd>
-            <dt id="failed_parse_docstring-6eef6">
-              <span class="m-doc-wrap-bumper">def <a href="#failed_parse_docstring-6eef6" class="m-doc-self">failed_parse_docstring</a>(</span><span class="m-doc-wrap">…)</span>
+            <dt id="failed_parse_docstring">
+              <span class="m-doc-wrap-bumper">def <a href="#failed_parse_docstring" class="m-doc-self">failed_parse_docstring</a>(</span><span class="m-doc-wrap">…)</span>
             </dt>
             <dd>A failed parse should &lt;strong&gt;also&lt;/strong&gt; escape the docstring</dd>
             <dt id="overloaded-46f8a">
               <span class="m-doc-wrap-bumper">def <a href="#overloaded-685e8" class="m-doc-self">overloaded</a>(</span><span class="m-doc-wrap">arg0: float<span class="m-text m-dim">, /</span>) -&gt; bool</span>
             </dt>
             <dd>Overloaded for floats</dd>
-            <dt id="scale-8f19c">
-              <span class="m-doc-wrap-bumper">def <a href="#scale-8f19c" class="m-doc-self">scale</a>(</span><span class="m-doc-wrap">arg0: int,
+            <dt id="scale">
+              <span class="m-doc-wrap-bumper">def <a href="#scale" class="m-doc-self">scale</a>(</span><span class="m-doc-wrap">arg0: int,
               arg1: float<span class="m-text m-dim">, /</span>) -&gt; int</span>
             </dt>
             <dd>Scale an integer</dd>
-            <dt id="scale_kwargs-8f19c">
-              <span class="m-doc-wrap-bumper">def <a href="#scale_kwargs-8f19c" class="m-doc-self">scale_kwargs</a>(</span><span class="m-doc-wrap">a: int,
+            <dt id="scale_kwargs">
+              <span class="m-doc-wrap-bumper">def <a href="#scale_kwargs" class="m-doc-self">scale_kwargs</a>(</span><span class="m-doc-wrap">a: int,
               argument: float) -&gt; int</span>
             </dt>
             <dd>Scale an integer, kwargs</dd>
-            <dt id="takes_a_function-515df">
-              <span class="m-doc-wrap-bumper">def <a href="#takes_a_function-515df" class="m-doc-self">takes_a_function</a>(</span><span class="m-doc-wrap">arg0: typing.Callable[[float, typing.List[float]], int]<span class="m-text m-dim">, /</span>) -&gt; None</span>
+            <dt id="takes_a_function">
+              <span class="m-doc-wrap-bumper">def <a href="#takes_a_function" class="m-doc-self">takes_a_function</a>(</span><span class="m-doc-wrap">arg0: typing.Callable[[float, typing.List[float]], int]<span class="m-text m-dim">, /</span>) -&gt; None</span>
             </dt>
             <dd>A function taking a Callable</dd>
-            <dt id="takes_a_function_returning_none-0a9eb">
-              <span class="m-doc-wrap-bumper">def <a href="#takes_a_function_returning_none-0a9eb" class="m-doc-self">takes_a_function_returning_none</a>(</span><span class="m-doc-wrap">arg0: typing.Callable[[], None]<span class="m-text m-dim">, /</span>) -&gt; None</span>
+            <dt id="takes_a_function_returning_none">
+              <span class="m-doc-wrap-bumper">def <a href="#takes_a_function_returning_none" class="m-doc-self">takes_a_function_returning_none</a>(</span><span class="m-doc-wrap">arg0: typing.Callable[[], None]<span class="m-text m-dim">, /</span>) -&gt; None</span>
             </dt>
             <dd>A function taking a Callable that returns None</dd>
-            <dt id="taking_a_list_returning_a_tuple-11ba6">
-              <span class="m-doc-wrap-bumper">def <a href="#taking_a_list_returning_a_tuple-11ba6" class="m-doc-self">taking_a_list_returning_a_tuple</a>(</span><span class="m-doc-wrap">arg0: typing.List[float]<span class="m-text m-dim">, /</span>) -&gt; typing.Tuple[int, int, int]</span>
+            <dt id="taking_a_list_returning_a_tuple">
+              <span class="m-doc-wrap-bumper">def <a href="#taking_a_list_returning_a_tuple" class="m-doc-self">taking_a_list_returning_a_tuple</a>(</span><span class="m-doc-wrap">arg0: typing.List[float]<span class="m-text m-dim">, /</span>) -&gt; typing.Tuple[int, int, int]</span>
             </dt>
             <dd>Takes a list, returns a tuple</dd>
             <dt id="tenOverloads-fe11a">
               arg1: str<span class="m-text m-dim">, /</span>) -&gt; None</span>
             </dt>
             <dd>Ten overloads of a function</dd>
-            <dt id="void_function-46f8a">
-              <span class="m-doc-wrap-bumper">def <a href="#void_function-46f8a" class="m-doc-self">void_function</a>(</span><span class="m-doc-wrap">arg0: int<span class="m-text m-dim">, /</span>) -&gt; None</span>
+            <dt id="void_function">
+              <span class="m-doc-wrap-bumper">def <a href="#void_function" class="m-doc-self">void_function</a>(</span><span class="m-doc-wrap">arg0: int<span class="m-text m-dim">, /</span>) -&gt; None</span>
             </dt>
             <dd>Returns nothing</dd>
           </dl>
index e08ebe78f6a96da003a6fdefc001c4c0525d128d..99c03c0685dfd0cc412dd069bccfb605e7e18869 100644 (file)
@@ -39,8 +39,8 @@
         <section id="dunder-methods">
           <h2><a href="#dunder-methods">Special methods</a></h2>
           <dl class="m-doc">
-            <dt id="__init__-8f54a">
-              <span class="m-doc-wrap-bumper">def <a href="#__init__-8f54a" class="m-doc-self">__init__</a>(</span><span class="m-doc-wrap">self,
+            <dt id="__init__">
+              <span class="m-doc-wrap-bumper">def <a href="#__init__" class="m-doc-self">__init__</a>(</span><span class="m-doc-wrap">self,
               arg0: <a href="pybind_type_links.html#Enum" class="m-doc">Enum</a><span class="m-text m-dim">, /</span>) -&gt; <a href="https://docs.python.org/3/library/constants.html#None" class="m-doc-external">None</a></span>
             </dt>
             <dd>Constructor</dd>
index c65bdb31f15ff014e8cbee3f4b09d11d4c9f0bbb..9c3c196570914e467ee4e4fe07d4c045edafc6f1 100644 (file)
         <section id="functions">
           <h2><a href="#functions">Functions</a></h2>
           <dl class="m-doc">
-            <dt id="type_enum-3b87d">
-              <span class="m-doc-wrap-bumper">def <a href="#type_enum-3b87d" class="m-doc-self">type_enum</a>(</span><span class="m-doc-wrap">value: <a href="pybind_type_links.html#Enum" class="m-doc">Enum</a> = <a href="pybind_type_links.html#Enum-SECOND" class="m-doc">Enum.SECOND</a>) -&gt; <a href="https://docs.python.org/3/library/constants.html#None" class="m-doc-external">None</a></span>
+            <dt id="type_enum">
+              <span class="m-doc-wrap-bumper">def <a href="#type_enum" class="m-doc-self">type_enum</a>(</span><span class="m-doc-wrap">value: <a href="pybind_type_links.html#Enum" class="m-doc">Enum</a> = <a href="pybind_type_links.html#Enum-SECOND" class="m-doc">Enum.SECOND</a>) -&gt; <a href="https://docs.python.org/3/library/constants.html#None" class="m-doc-external">None</a></span>
             </dt>
             <dd>A function taking an enum</dd>
-            <dt id="type_nested-0e174">
-              <span class="m-doc-wrap-bumper">def <a href="#type_nested-0e174" class="m-doc-self">type_nested</a>(</span><span class="m-doc-wrap">arg0: <a href="https://docs.python.org/3/library/typing.html#typing.Tuple" class="m-doc-external">typing.Tuple</a>[<a href="pybind_type_links.Foo.html" class="m-doc">Foo</a>, <a href="https://docs.python.org/3/library/typing.html#typing.List" class="m-doc-external">typing.List</a>[<a href="pybind_type_links.html#Enum" class="m-doc">Enum</a>]]<span class="m-text m-dim">, /</span>) -&gt; <a href="https://docs.python.org/3/library/constants.html#None" class="m-doc-external">None</a></span>
+            <dt id="type_nested">
+              <span class="m-doc-wrap-bumper">def <a href="#type_nested" class="m-doc-self">type_nested</a>(</span><span class="m-doc-wrap">arg0: <a href="https://docs.python.org/3/library/typing.html#typing.Tuple" class="m-doc-external">typing.Tuple</a>[<a href="pybind_type_links.Foo.html" class="m-doc">Foo</a>, <a href="https://docs.python.org/3/library/typing.html#typing.List" class="m-doc-external">typing.List</a>[<a href="pybind_type_links.html#Enum" class="m-doc">Enum</a>]]<span class="m-text m-dim">, /</span>) -&gt; <a href="https://docs.python.org/3/library/constants.html#None" class="m-doc-external">None</a></span>
             </dt>
             <dd>A function with nested type annotation</dd>
-            <dt id="type_return-da39a">
-              <span class="m-doc-wrap-bumper">def <a href="#type_return-da39a" class="m-doc-self">type_return</a>(</span><span class="m-doc-wrap">) -&gt; <a href="pybind_type_links.Foo.html" class="m-doc">Foo</a></span>
+            <dt id="type_return">
+              <span class="m-doc-wrap-bumper">def <a href="#type_return" class="m-doc-self">type_return</a>(</span><span class="m-doc-wrap">) -&gt; <a href="pybind_type_links.Foo.html" class="m-doc">Foo</a></span>
             </dt>
             <dd>A function returning a type</dd>
           </dl>
index eae9ef2cabdbda30801c0236e06d6f863f46a131..a0a684afea7f01c91a442d4d623d081897bf880c 100644 (file)
@@ -43,7 +43,7 @@ class Search(BaseInspectTestCase):
             serialized = f.read()
             search_data_pretty = pretty_print(serialized, entryTypeClass=EntryType)[0]
         #print(search_data_pretty)
-        self.assertEqual(len(serialized), 2088)
+        self.assertEqual(len(serialized), 2076)
         self.assertEqual(search_data_pretty, """
 19 symbols
 search [12]
@@ -158,10 +158,10 @@ overloaded_method [15, 17, 13]
 17: .overloaded_method(self, arg0: int, arg1: Foo) [prefix=19[:22], suffix_length=28, type=FUNCTION] -> #overloaded_method-41cfb
 18:  [prefix=17[:46], suffix_length=26, type=FUNCTION] ->
 19: .Foo [prefix=24[:14], type=CLASS] -> Foo.html
-20: .function() [prefix=24[:18], suffix_length=2, type=FUNCTION] -> #function-da39a
-21:  [prefix=20[:33], type=FUNCTION] ->
-22: .function_with_params() [prefix=24[:18], suffix_length=2, type=FUNCTION] -> #function_with_params-8f19c
-23:  [prefix=22[:45], type=FUNCTION] ->
+20: .function() [prefix=24[:18], suffix_length=2, type=FUNCTION] -> #function
+21:  [prefix=20[:27], type=FUNCTION] ->
+22: .function_with_params() [prefix=24[:18], suffix_length=2, type=FUNCTION] -> #function_with_params
+23:  [prefix=22[:39], type=FUNCTION] ->
 24: .pybind [prefix=12[:7], type=MODULE] -> pybind.html
 25: .DATA_IN_A_SUBMODULE [prefix=26[:15], type=DATA] -> #DATA_IN_A_SUBMODULE
 26: .sub [prefix=12[:7], type=MODULE] -> sub.html