The overload signatures of __init__ methods are documented

Fixes #260
This commit is contained in:
Ashley Whetter 2021-01-31 15:34:40 -08:00
parent 73bb2d6105
commit 24109875e1
4 changed files with 35 additions and 1 deletions

View File

@ -13,6 +13,12 @@ Features
so that Sphinx can link to them. so that Sphinx can link to them.
* Added support for Sphinx 3.3. and 3.4. * Added support for Sphinx 3.3. and 3.4.
Bug Fixes
^^^^^^^^^
* `#260 <https://github.com/readthedocs/sphinx-autoapi/issues/260>`:
The overload signatures of ``__init__`` methods are documented.
V1.6.0 (2021-01-20) V1.6.0 (2021-01-20)
------------------- -------------------
@ -54,6 +60,7 @@ V1.5.1 (2020-10-01)
Bug Fixes Bug Fixes
^^^^^^^^^ ^^^^^^^^^
* Fixed AttributeError when generating an inheritance diagram for a module. * Fixed AttributeError when generating an inheritance diagram for a module.

View File

@ -1,5 +1,12 @@
{% if obj.display %} {% if obj.display %}
.. py:{{ obj.type }}:: {{ obj.short_name }}{% if obj.args %}({{ obj.args }}){% endif %} .. {{ obj.type }}:: {{ obj.short_name }}{% if obj.args %}({{ obj.args }}){% endif %}
{% if obj.constructor %}
{% for (args, return_annotation) in obj.constructor.overloads %}
{% if args and args.startswith("self, ") %}{% set args = args[6:] %}{% endif %}
{{ " " * (obj.type | length) }} {{ obj.short_name }}{% if args %}({{ args }}){% endif %}
{% endfor %}
{% endif %}
{% if obj.bases %} {% if obj.bases %}

View File

@ -126,6 +126,19 @@ class A:
return a * 2 return a * 2
class C:
@overload
def __init__(self, a: int) -> None:
...
@typing.overload
def __init__(self, a: float) -> None:
...
def __init__(self, a: str):
...
async def async_function(wait: bool) -> int: async def async_function(wait: bool) -> int:
"""Blah. """Blah.

View File

@ -219,6 +219,13 @@ class TestPy3Module(object):
assert "undoc_overloaded_func" in example_file assert "undoc_overloaded_func" in example_file
assert "undoc_overloaded_method" in example_file assert "undoc_overloaded_method" in example_file
assert "C(a: int" in example_file
assert "C(a: float" in example_file
assert "C(a: str" not in example_file
assert "C(self, a: int" not in example_file
assert "C(self, a: float" not in example_file
assert "C(self, a: str" not in example_file
def test_async(self): def test_async(self):
example_path = "_build/text/autoapi/example/index.txt" example_path = "_build/text/autoapi/example/index.txt"
with io.open(example_path, encoding="utf8") as example_handle: with io.open(example_path, encoding="utf8") as example_handle: