mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #10280: autodoc_docstring_signature generates needless return typehint
Basically, autodoc suppresses return value typehint for class constructors. But it was unexpectedly shown if `autodoc_docstring_signature` is enabled and docstring has multiple signatures.
This commit is contained in:
parent
33610201dc
commit
a78c07ca07
2
CHANGES
2
CHANGES
@ -67,6 +67,8 @@ Bugs fixed
|
|||||||
|
|
||||||
* #10279: autodoc: Default values for keyword only arguments in overloaded
|
* #10279: autodoc: Default values for keyword only arguments in overloaded
|
||||||
functions are rendered as a string literal
|
functions are rendered as a string literal
|
||||||
|
* #10280: autodoc: :confval:`autodoc_docstring_signature` unexpectedly generates
|
||||||
|
return value typehint for constructors if docstring has multiple signatures
|
||||||
* #10214: html: invalid language tag was generated if :confval:`language`
|
* #10214: html: invalid language tag was generated if :confval:`language`
|
||||||
contains a country code (ex. zh_CN)
|
contains a country code (ex. zh_CN)
|
||||||
* #10236: html search: objects are duplicated in search result
|
* #10236: html search: objects are duplicated in search result
|
||||||
|
@ -1580,6 +1580,20 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
|
|||||||
|
|
||||||
return stringify_signature(sig, show_return_annotation=False, **kwargs)
|
return stringify_signature(sig, show_return_annotation=False, **kwargs)
|
||||||
|
|
||||||
|
def _find_signature(self) -> Tuple[str, str]:
|
||||||
|
result = super()._find_signature()
|
||||||
|
if result is not None:
|
||||||
|
# Strip a return value from signature of constructor in docstring (first entry)
|
||||||
|
result = (result[0], None)
|
||||||
|
|
||||||
|
for i, sig in enumerate(self._signatures):
|
||||||
|
if sig.endswith(' -> None'):
|
||||||
|
# Strip a return value from signatures of constructor in docstring (subsequent
|
||||||
|
# entries)
|
||||||
|
self._signatures[i] = sig[:-8]
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def format_signature(self, **kwargs: Any) -> str:
|
def format_signature(self, **kwargs: Any) -> str:
|
||||||
if self.doc_as_attr:
|
if self.doc_as_attr:
|
||||||
return ''
|
return ''
|
||||||
|
@ -22,10 +22,12 @@ class D:
|
|||||||
class E:
|
class E:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""E(foo: int, bar: int, baz: int) -> None \\
|
"""E(foo: int, bar: int, baz: int) -> None \\
|
||||||
E(foo: str, bar: str, baz: str) -> None"""
|
E(foo: str, bar: str, baz: str) -> None \\
|
||||||
|
E(foo: float, bar: float, baz: float)"""
|
||||||
|
|
||||||
|
|
||||||
class F:
|
class F:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""F(foo: int, bar: int, baz: int) -> None
|
"""F(foo: int, bar: int, baz: int) -> None
|
||||||
F(foo: str, bar: str, baz: str) -> None"""
|
F(foo: str, bar: str, baz: str) -> None
|
||||||
|
F(foo: float, bar: float, baz: float)"""
|
||||||
|
@ -467,13 +467,15 @@ def test_autoclass_content_and_docstring_signature_init(app):
|
|||||||
' :module: target.docstring_signature',
|
' :module: target.docstring_signature',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'.. py:class:: E(foo: int, bar: int, baz: int) -> None',
|
'.. py:class:: E(foo: int, bar: int, baz: int)',
|
||||||
' E(foo: str, bar: str, baz: str) -> None',
|
' E(foo: str, bar: str, baz: str)',
|
||||||
|
' E(foo: float, bar: float, baz: float)',
|
||||||
' :module: target.docstring_signature',
|
' :module: target.docstring_signature',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'.. py:class:: F(foo: int, bar: int, baz: int) -> None',
|
'.. py:class:: F(foo: int, bar: int, baz: int)',
|
||||||
' F(foo: str, bar: str, baz: str) -> None',
|
' F(foo: str, bar: str, baz: str)',
|
||||||
|
' F(foo: float, bar: float, baz: float)',
|
||||||
' :module: target.docstring_signature',
|
' :module: target.docstring_signature',
|
||||||
'',
|
'',
|
||||||
]
|
]
|
||||||
@ -510,13 +512,15 @@ def test_autoclass_content_and_docstring_signature_both(app):
|
|||||||
' :module: target.docstring_signature',
|
' :module: target.docstring_signature',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'.. py:class:: E(foo: int, bar: int, baz: int) -> None',
|
'.. py:class:: E(foo: int, bar: int, baz: int)',
|
||||||
' E(foo: str, bar: str, baz: str) -> None',
|
' E(foo: str, bar: str, baz: str)',
|
||||||
|
' E(foo: float, bar: float, baz: float)',
|
||||||
' :module: target.docstring_signature',
|
' :module: target.docstring_signature',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'.. py:class:: F(foo: int, bar: int, baz: int) -> None',
|
'.. py:class:: F(foo: int, bar: int, baz: int)',
|
||||||
' F(foo: str, bar: str, baz: str) -> None',
|
' F(foo: str, bar: str, baz: str)',
|
||||||
|
' F(foo: float, bar: float, baz: float)',
|
||||||
' :module: target.docstring_signature',
|
' :module: target.docstring_signature',
|
||||||
'',
|
'',
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user