mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #8841 from AWhetter/autodoc_signatures_without_backslash
Overloaded function signatures do not require a separating backslash
This commit is contained in:
commit
70ea4381ca
@ -529,15 +529,19 @@ There are also config values that you can set:
|
|||||||
looks like a signature, use the line as the signature and remove it from the
|
looks like a signature, use the line as the signature and remove it from the
|
||||||
docstring content.
|
docstring content.
|
||||||
|
|
||||||
If the signature line ends with backslash, autodoc considers the function has
|
autodoc will continue to look for multiple signature lines,
|
||||||
multiple signatures and look at the next line of the docstring. It is useful
|
stopping at the first line that does not look like a signature.
|
||||||
for overloaded function.
|
This is useful for declaring overloaded function signatures.
|
||||||
|
|
||||||
.. versionadded:: 1.1
|
.. versionadded:: 1.1
|
||||||
.. versionchanged:: 3.1
|
.. versionchanged:: 3.1
|
||||||
|
|
||||||
Support overloaded signatures
|
Support overloaded signatures
|
||||||
|
|
||||||
|
.. versionchanged:: 4.0
|
||||||
|
|
||||||
|
Overloaded signatures do not need to be separated by a backslash
|
||||||
|
|
||||||
.. confval:: autodoc_mock_imports
|
.. confval:: autodoc_mock_imports
|
||||||
|
|
||||||
This value contains a list of modules to be mocked up. This is useful when
|
This value contains a list of modules to be mocked up. This is useful when
|
||||||
|
@ -1191,20 +1191,17 @@ class DocstringSignatureMixin:
|
|||||||
break
|
break
|
||||||
|
|
||||||
if line.endswith('\\'):
|
if line.endswith('\\'):
|
||||||
multiline = True
|
|
||||||
line = line.rstrip('\\').rstrip()
|
line = line.rstrip('\\').rstrip()
|
||||||
else:
|
|
||||||
multiline = False
|
|
||||||
|
|
||||||
# match first line of docstring against signature RE
|
# match first line of docstring against signature RE
|
||||||
match = py_ext_sig_re.match(line)
|
match = py_ext_sig_re.match(line)
|
||||||
if not match:
|
if not match:
|
||||||
continue
|
break
|
||||||
exmod, path, base, args, retann = match.groups()
|
exmod, path, base, args, retann = match.groups()
|
||||||
|
|
||||||
# the base name must match ours
|
# the base name must match ours
|
||||||
if base not in valid_names:
|
if base not in valid_names:
|
||||||
continue
|
break
|
||||||
|
|
||||||
# re-prepare docstring to ignore more leading indentation
|
# re-prepare docstring to ignore more leading indentation
|
||||||
tab_width = self.directive.state.document.settings.tab_width # type: ignore
|
tab_width = self.directive.state.document.settings.tab_width # type: ignore
|
||||||
@ -1218,13 +1215,6 @@ class DocstringSignatureMixin:
|
|||||||
# subsequent signatures
|
# subsequent signatures
|
||||||
self._signatures.append("(%s) -> %s" % (args, retann))
|
self._signatures.append("(%s) -> %s" % (args, retann))
|
||||||
|
|
||||||
if multiline:
|
|
||||||
# the signature have multiple signatures on docstring
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
# don't look any further
|
|
||||||
break
|
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
# finish the loop when signature found
|
# finish the loop when signature found
|
||||||
break
|
break
|
||||||
|
@ -23,3 +23,9 @@ 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"""
|
||||||
|
|
||||||
|
|
||||||
|
class F:
|
||||||
|
def __init__(self):
|
||||||
|
"""F(foo: int, bar: int, baz: int) -> None
|
||||||
|
F(foo: str, bar: str, baz: str) -> None"""
|
||||||
|
@ -348,7 +348,11 @@ def test_autoclass_content_and_docstring_signature_class(app):
|
|||||||
'',
|
'',
|
||||||
'.. py:class:: E()',
|
'.. py:class:: E()',
|
||||||
' :module: target.docstring_signature',
|
' :module: target.docstring_signature',
|
||||||
''
|
'',
|
||||||
|
'',
|
||||||
|
'.. py:class:: F()',
|
||||||
|
' :module: target.docstring_signature',
|
||||||
|
'',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -382,7 +386,12 @@ def test_autoclass_content_and_docstring_signature_init(app):
|
|||||||
'.. py:class:: E(foo: int, bar: int, baz: int) -> None',
|
'.. py:class:: E(foo: int, bar: int, baz: int) -> None',
|
||||||
' E(foo: str, bar: str, baz: str) -> None',
|
' E(foo: str, bar: str, baz: str) -> None',
|
||||||
' :module: target.docstring_signature',
|
' :module: target.docstring_signature',
|
||||||
''
|
'',
|
||||||
|
'',
|
||||||
|
'.. py:class:: F(foo: int, bar: int, baz: int) -> None',
|
||||||
|
' F(foo: str, bar: str, baz: str) -> None',
|
||||||
|
' :module: target.docstring_signature',
|
||||||
|
'',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -421,6 +430,11 @@ def test_autoclass_content_and_docstring_signature_both(app):
|
|||||||
' E(foo: str, bar: str, baz: str) -> None',
|
' E(foo: str, bar: str, baz: str) -> None',
|
||||||
' :module: target.docstring_signature',
|
' :module: target.docstring_signature',
|
||||||
'',
|
'',
|
||||||
|
'',
|
||||||
|
'.. py:class:: F(foo: int, bar: int, baz: int) -> None',
|
||||||
|
' F(foo: str, bar: str, baz: str) -> None',
|
||||||
|
' :module: target.docstring_signature',
|
||||||
|
'',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user