Skip to content

Commit

Permalink
The overload signatures of __init__ methods are documented
Browse files Browse the repository at this point in the history
Fixes #260
  • Loading branch information
AWhetter committed Jan 31, 2021
1 parent 73bb2d6 commit 2410987
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Features
so that Sphinx can link to them.
* 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)
-------------------
Expand Down Expand Up @@ -54,6 +60,7 @@ V1.5.1 (2020-10-01)

Bug Fixes
^^^^^^^^^

* Fixed AttributeError when generating an inheritance diagram for a module.


Expand Down
9 changes: 8 additions & 1 deletion autoapi/templates/python/class.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{% 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 %}
Expand Down
13 changes: 13 additions & 0 deletions tests/python/py3example/example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ def overloaded_class_method(cls, a: Union[float, str]) -> Union[float, str]:
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:
"""Blah.
Expand Down
7 changes: 7 additions & 0 deletions tests/python/test_pyintegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ def test_overload(self):
assert "undoc_overloaded_func" 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):
example_path = "_build/text/autoapi/example/index.txt"
with io.open(example_path, encoding="utf8") as example_handle:
Expand Down

0 comments on commit 2410987

Please sign in to comment.