From ef5ace6e599f30896cdb9f024c030290bb0d1461 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 10 Sep 2019 19:30:09 +0200 Subject: [PATCH] documentation/python: format overloaded func ID only if it's overloaded. 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 | 9 +++-- .../c.link_formatting.pybind.Foo.html | 12 +++--- .../m.link_formatting.pybind.html | 4 +- .../pybind_name_mapping.Class.html | 4 +- .../pybind_name_mapping.submodule.html | 4 +- .../pybind_signatures.MyClass.html | 20 +++++----- .../pybind_signatures/pybind_signatures.html | 40 +++++++++---------- .../pybind_type_links.Foo.html | 4 +- .../pybind_type_links/pybind_type_links.html | 12 +++--- documentation/test_python/test_search.py | 10 ++--- 10 files changed, 61 insertions(+), 58 deletions(-) diff --git a/documentation/python.py b/documentation/python.py index 582451b3..36cd04f9 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -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: diff --git a/documentation/test_python/link_formatting/c.link_formatting.pybind.Foo.html b/documentation/test_python/link_formatting/c.link_formatting.pybind.Foo.html index 77b0a748..6e37feeb 100644 --- a/documentation/test_python/link_formatting/c.link_formatting.pybind.Foo.html +++ b/documentation/test_python/link_formatting/c.link_formatting.pybind.Foo.html @@ -56,8 +56,8 @@

Static methods

-
- def a_function(arg0: int, /) -> int +
+ def a_function(arg0: int, /) -> int
A static function that should have the same hash as takes_int()
@@ -65,13 +65,13 @@

Methods

-
- def bar(self, +
+ def bar(self, arg0: int, /) -> int
Should have the same hash as foo() but not as a_function()
-
- def foo(self, +
+ def foo(self, arg0: int, /) -> int
Should have the same hash as bar() but not as a_function()
diff --git a/documentation/test_python/link_formatting/m.link_formatting.pybind.html b/documentation/test_python/link_formatting/m.link_formatting.pybind.html index 7f47d9d2..b0152d3e 100644 --- a/documentation/test_python/link_formatting/m.link_formatting.pybind.html +++ b/documentation/test_python/link_formatting/m.link_formatting.pybind.html @@ -77,8 +77,8 @@ arg1: Foo, /) -> int
Each overload should have a different hash
-
- def takes_int(arg0: int, /) -> int +
+ def takes_int(arg0: int, /) -> int
Should have the same hash as Foo.a_function()
diff --git a/documentation/test_python/pybind_name_mapping/pybind_name_mapping.Class.html b/documentation/test_python/pybind_name_mapping/pybind_name_mapping.Class.html index 94c16d83..246af4ea 100644 --- a/documentation/test_python/pybind_name_mapping/pybind_name_mapping.Class.html +++ b/documentation/test_python/pybind_name_mapping/pybind_name_mapping.Class.html @@ -37,8 +37,8 @@

Static methods

-
- def a_thing() -> Class +
+ def a_thing() -> Class
A method
diff --git a/documentation/test_python/pybind_name_mapping/pybind_name_mapping.submodule.html b/documentation/test_python/pybind_name_mapping/pybind_name_mapping.submodule.html index 58683c8e..a50521e1 100644 --- a/documentation/test_python/pybind_name_mapping/pybind_name_mapping.submodule.html +++ b/documentation/test_python/pybind_name_mapping/pybind_name_mapping.submodule.html @@ -37,8 +37,8 @@

Functions

-
- def foo(arg0: Class, +
+ def foo(arg0: Class, arg1: int, /) -> int
A function
diff --git a/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html b/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html index 7d1628c6..5343d0ce 100644 --- a/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html +++ b/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html @@ -40,8 +40,8 @@

Static methods

-
- def static_function(arg0: int, +
+ def static_function(arg0: int, arg1: float, /) -> MyClass
Static method with positional-only args
@@ -50,18 +50,18 @@

Methods

-
- def another(self, /) -> int +
+ def another(self, /) -> int
Instance method with no args, 'self' is thus position-only
-
- def instance_function(self, +
+ def instance_function(self, arg0: int, arg1: str, /) -> typing.Tuple[float, int]
Instance method with positional-only args
-
- def instance_function_kwargs(self, +
+ def instance_function_kwargs(self, hey: int, what: str = '<eh?>') -> typing.Tuple[float, int]
@@ -71,8 +71,8 @@

Special methods

-
- def __init__(self, /) -> None +
+ def __init__(self, /) -> None
Constructor
diff --git a/documentation/test_python/pybind_signatures/pybind_signatures.html b/documentation/test_python/pybind_signatures/pybind_signatures.html index 2ff53e07..832b92ed 100644 --- a/documentation/test_python/pybind_signatures/pybind_signatures.html +++ b/documentation/test_python/pybind_signatures/pybind_signatures.html @@ -47,20 +47,20 @@

Functions

-
- def crazy_signature(…) +
+ def crazy_signature(…)
Function that failed to get parsed
-
- def duck(*args, **kwargs) -> None +
+ def duck(*args, **kwargs) -> None
A function taking args/kwargs directly
-
- def escape_docstring(arg0: int, /) -> None +
+ def escape_docstring(arg0: int, /) -> None
A docstring that <em>should</em> be escaped
-
- def failed_parse_docstring(…) +
+ def failed_parse_docstring(…)
A failed parse should <strong>also</strong> escape the docstring
@@ -71,26 +71,26 @@ def overloaded(arg0: float, /) -> bool
Overloaded for floats
-
- def scale(arg0: int, +
+ def scale(arg0: int, arg1: float, /) -> int
Scale an integer
-
- def scale_kwargs(a: int, +
+ def scale_kwargs(a: int, argument: float) -> int
Scale an integer, kwargs
-
- def takes_a_function(arg0: typing.Callable[[float, typing.List[float]], int], /) -> None +
+ def takes_a_function(arg0: typing.Callable[[float, typing.List[float]], int], /) -> None
A function taking a Callable
-
- def takes_a_function_returning_none(arg0: typing.Callable[[], None], /) -> None +
+ def takes_a_function_returning_none(arg0: typing.Callable[[], None], /) -> None
A function taking a Callable that returns None
-
- def taking_a_list_returning_a_tuple(arg0: typing.List[float], /) -> typing.Tuple[int, int, int] +
+ def taking_a_list_returning_a_tuple(arg0: typing.List[float], /) -> typing.Tuple[int, int, int]
Takes a list, returns a tuple
@@ -143,8 +143,8 @@ arg1: str, /) -> None
Ten overloads of a function
-
- def void_function(arg0: int, /) -> None +
+ def void_function(arg0: int, /) -> None
Returns nothing
diff --git a/documentation/test_python/pybind_type_links/pybind_type_links.Foo.html b/documentation/test_python/pybind_type_links/pybind_type_links.Foo.html index e08ebe78..99c03c06 100644 --- a/documentation/test_python/pybind_type_links/pybind_type_links.Foo.html +++ b/documentation/test_python/pybind_type_links/pybind_type_links.Foo.html @@ -39,8 +39,8 @@

Special methods

-
- def __init__(self, +
+ def __init__(self, arg0: Enum, /) -> None
Constructor
diff --git a/documentation/test_python/pybind_type_links/pybind_type_links.html b/documentation/test_python/pybind_type_links/pybind_type_links.html index c65bdb31..9c3c1965 100644 --- a/documentation/test_python/pybind_type_links/pybind_type_links.html +++ b/documentation/test_python/pybind_type_links/pybind_type_links.html @@ -57,16 +57,16 @@

Functions

-
- def type_enum(value: Enum = Enum.SECOND) -> None +
+ def type_enum(value: Enum = Enum.SECOND) -> None
A function taking an enum
-
- def type_nested(arg0: typing.Tuple[Foo, typing.List[Enum]], /) -> None +
+ def type_nested(arg0: typing.Tuple[Foo, typing.List[Enum]], /) -> None
A function with nested type annotation
-
- def type_return() -> Foo +
+ def type_return() -> Foo
A function returning a type
diff --git a/documentation/test_python/test_search.py b/documentation/test_python/test_search.py index eae9ef2c..a0a684af 100644 --- a/documentation/test_python/test_search.py +++ b/documentation/test_python/test_search.py @@ -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 -- 2.30.2