diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-10-28 11:02:25 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-28 11:02:25 +0900 |
commit | 293dced4d4213d924310160a112d0907e02f8059 (patch) | |
tree | 594c76c23df106099a8738373e2a0a195913d23b | |
parent | 2c2335bbb8af99fa132e1573bbf45dc91584d5a2 (diff) | |
parent | 871f43f77837d7e668fcaac8d22cdeaff3d7b8e0 (diff) | |
download | sphinx-git-293dced4d4213d924310160a112d0907e02f8059.tar.gz |
Merge pull request #8282 from tk0miya/7785_autodoc_typehints_none_for_overloads
Fix #7785: autodoc_typehints=none does not effect to overloads
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | sphinx/ext/autodoc/__init__.py | 10 | ||||
-rw-r--r-- | tests/test_ext_autodoc_configs.py | 48 |
3 files changed, 56 insertions, 3 deletions
@@ -48,6 +48,7 @@ Bugs fixed * #8200: autodoc: type aliases break type formatting of autoattribute * #7786: autodoc: can't detect overloaded methods defined in other file * #8294: autodoc: single-string __slots__ is not handled correctly +* #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 diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 978fd5df8..7343d41b6 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1240,7 +1240,9 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ 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 == 'signature'): # Use signatures for overloaded functions instead of the implementation function. overloaded = True else: @@ -1474,7 +1476,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: sigs = [] overloads = self.get_overloaded_signatures() - if overloads: + if overloads and self.env.config.autodoc_typehints == 'signature': # Use signatures for overloaded methods instead of the implementation method. method = safe_getattr(self._signature_class, self._signature_method_name, None) __globals__ = safe_getattr(method, '__globals__', {}) @@ -1882,7 +1884,9 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type: 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 == 'signature'): # Use signatures for overloaded methods instead of the implementation method. overloaded = True else: diff --git a/tests/test_ext_autodoc_configs.py b/tests/test_ext_autodoc_configs.py index 7d51b7f0e..8ebe12d40 100644 --- a/tests/test_ext_autodoc_configs.py +++ b/tests/test_ext_autodoc_configs.py @@ -610,6 +610,54 @@ def test_autodoc_typehints_none(app): ] +@pytest.mark.sphinx('html', testroot='ext-autodoc', + confoverrides={'autodoc_typehints': 'none'}) +def test_autodoc_typehints_none_for_overload(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('text', testroot='ext-autodoc', confoverrides={'autodoc_typehints': "description"}) def test_autodoc_typehints_description(app): |