Skip to content

Commit

Permalink
Fix sphinx-doc#7785: autodoc_typehints=none does not effect to overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Oct 4, 2020
1 parent 941c9ba commit ff55e61
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -39,6 +39,7 @@ Bugs fixed
typing.Generic
* #8157: autodoc: TypeError is raised when annotation has invalid __args__
* #7964: autodoc: Tuple in default value is wrongly rendered
* #7785: autodoc: autodoc_typehints='none' does not effect to overloaded functions
* #8192: napoleon: description is disappeared when it contains inline literals
* #8142: napoleon: Potential of regex denial of service in google style docs
* #8169: LaTeX: pxjahyper loaded even when latex_engine is not platex
Expand Down
12 changes: 9 additions & 3 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -1240,7 +1240,9 @@ def add_directive_header(self, sig: str) -> None:

def format_signature(self, **kwargs: Any) -> str:
sigs = []
if self.analyzer and '.'.join(self.objpath) in self.analyzer.overloads:
if (self.analyzer and
'.'.join(self.objpath) in self.analyzer.overloads and
self.env.config.autodoc_typehints not in ('none', 'description')):
# Use signatures for overloaded functions instead of the implementation function.
overloaded = True
else:
Expand Down Expand Up @@ -1475,7 +1477,9 @@ def format_signature(self, **kwargs: Any) -> str:
overloaded = False
qualname = None
# TODO: recreate analyzer for the module of class (To be clear, owner of the method)
if self._signature_class and self._signature_method_name and self.analyzer:
if (self._signature_class and
self._signature_method_name and self.analyzer and
self.env.config.autodoc_typehints not in ('none', 'description')):
qualname = '.'.join([self._signature_class.__qualname__,
self._signature_method_name])
if qualname in self.analyzer.overloads:
Expand Down Expand Up @@ -1874,7 +1878,9 @@ def document_members(self, all_members: bool = False) -> None:

def format_signature(self, **kwargs: Any) -> str:
sigs = []
if self.analyzer and '.'.join(self.objpath) in self.analyzer.overloads:
if (self.analyzer and
'.'.join(self.objpath) in self.analyzer.overloads and
self.env.config.autodoc_typehints not in ('none', 'description')):
# Use signatures for overloaded methods instead of the implementation method.
overloaded = True
else:
Expand Down
48 changes: 48 additions & 0 deletions tests/test_ext_autodoc.py
Expand Up @@ -1948,6 +1948,54 @@ def test_final(app):
]


@pytest.mark.sphinx('html', testroot='ext-autodoc',
confoverrides={'autodoc_typehints': 'none'})
def test_overload_autodoc_typehints_none(app):
options = {"members": None}
actual = do_autodoc(app, 'module', 'target.overload', options)
assert list(actual) == [
'',
'.. py:module:: target.overload',
'',
'',
'.. py:class:: Bar(x, y)',
' :module: target.overload',
'',
' docstring',
'',
'',
'.. py:class:: Baz(x, y)',
' :module: target.overload',
'',
' docstring',
'',
'',
'.. py:class:: Foo(x, y)',
' :module: target.overload',
'',
' docstring',
'',
'',
'.. py:class:: Math()',
' :module: target.overload',
'',
' docstring',
'',
'',
' .. py:method:: Math.sum(x, y)',
' :module: target.overload',
'',
' docstring',
'',
'',
'.. py:function:: sum(x, y)',
' :module: target.overload',
'',
' docstring',
'',
]


@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_overload(app):
options = {"members": None}
Expand Down

0 comments on commit ff55e61

Please sign in to comment.