diff --git a/CHANGES b/CHANGES index 5a39388ec..5feb5bbf3 100644 --- a/CHANGES +++ b/CHANGES @@ -149,6 +149,8 @@ Bugs fixed "variadic templates" declarations. Thanks to Victor Zverovich. * #1459,PR#244: Fix default mathjax js path point to `http://` that cause mixed-content error on HTTPS server. Thanks to sbrandtb and robo9k. +* PR#157: autodoc remove spurious signatures from @property decorated + attributes. Thanks to David Ham. Documentation ------------- diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 8766e391c..bd947b440 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -982,7 +982,10 @@ class DocstringStripSignatureMixin(DocstringSignatureMixin): # the feature is enabled result = self._find_signature() if result is not None: - self.retann = result[1] + # Discarding _args is a only difference with + # DocstringSignatureMixin.format_signature. + # Documenter.format_signature use self.args value to format. + _args, self.retann = result return Documenter.format_signature(self) diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index 06b86568c..d100b5550 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -415,6 +415,39 @@ def test_docstring_processing(): app.disconnect(lid) +@with_setup(setup_test) +def test_docstring_property_processing(): + def genarate_docstring(objtype, name, **kw): + del processed_docstrings[:] + del processed_signatures[:] + inst = AutoDirective._registry[objtype](directive, name) + inst.generate(**kw) + results = list(directive.result) + docstrings = inst.get_doc()[0] + del directive.result[:] + return results, docstrings + + directive.env.config.autodoc_docstring_signature = False + results, docstrings = genarate_docstring('attribute', 'test_autodoc.DocstringSig.prop1') + assert '.. py:attribute:: DocstringSig.prop1' in results + assert 'First line of docstring' in docstrings + assert 'DocstringSig.prop1(self)' in docstrings + results, docstrings = genarate_docstring('attribute', 'test_autodoc.DocstringSig.prop2') + assert '.. py:attribute:: DocstringSig.prop2' in results + assert 'First line of docstring' in docstrings + assert 'Second line of docstring' in docstrings + + directive.env.config.autodoc_docstring_signature = True + results, docstrings = genarate_docstring('attribute', 'test_autodoc.DocstringSig.prop1') + assert '.. py:attribute:: DocstringSig.prop1' in results + assert 'First line of docstring' in docstrings + assert 'DocstringSig.prop1(self)' not in docstrings + results, docstrings = genarate_docstring('attribute', 'test_autodoc.DocstringSig.prop2') + assert '.. py:attribute:: DocstringSig.prop2' in results + assert 'First line of docstring' in docstrings + assert 'Second line of docstring' in docstrings + + @with_setup(setup_test) def test_new_documenter(): class MyDocumenter(ModuleLevelDocumenter): @@ -873,6 +906,20 @@ First line of docstring indented line """ + @property + def prop1(self): + """DocstringSig.prop1(self) + First line of docstring + """ + return 123 + + @property + def prop2(self): + """First line of docstring + Second line of docstring + """ + return 456 + class StrRepr(str): def __repr__(self): return self