Skip to content

Commit 4fb6130

Browse files
committed
sphinx.ext.napoleon: Don't indent empty lines
Signed-off-by: Stephen Finucane <[email protected]>
1 parent 34403ad commit 4fb6130

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

sphinx/ext/napoleon/docstring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def _get_min_indent(self, lines: list[str]) -> int:
534534
return min_indent or 0
535535

536536
def _indent(self, lines: list[str], n: int = 4) -> list[str]:
537-
return [(' ' * n) + line for line in lines]
537+
return [(' ' * n) + line if line else line for line in lines]
538538

539539
def _is_indented(self, line: str, indent: int = 1) -> bool:
540540
for i, s in enumerate(line): # noqa: SIM110

tests/test_ext_napoleon_docstring.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,11 @@ def test_sphinx_admonitions(self):
397397
# Multiline
398398
actual = str(GoogleDocstring(f"{section}:\n"
399399
" this is the first line\n"
400-
"\n"
401400
" and this is the second line\n",
402401
config))
403402
expect = (f".. {admonition}::\n"
404403
"\n"
405404
" this is the first line\n"
406-
" \n"
407405
" and this is the second line\n"
408406
)
409407
assert expect == actual
@@ -1154,7 +1152,7 @@ def test_noindex(self):
11541152
.. method:: func(i, j)
11551153
:no-index:
11561154
1157-
1155+
11581156
description
11591157
""" # noqa: W293
11601158
config = Config()
@@ -1459,13 +1457,11 @@ def test_sphinx_admonitions(self):
14591457
actual = str(NumpyDocstring(f"{section}\n"
14601458
f"{'-' * len(section)}\n"
14611459
" this is the first line\n"
1462-
"\n"
14631460
" and this is the second line\n",
14641461
config))
14651462
expect = (f".. {admonition}::\n"
14661463
"\n"
14671464
" this is the first line\n"
1468-
" \n"
14691465
" and this is the second line\n"
14701466
)
14711467
assert expect == actual
@@ -1610,7 +1606,7 @@ def test_see_also_refs(self):
16101606
.. seealso::
16111607
16121608
:obj:`some`, :obj:`other`, :obj:`funcs`
1613-
\n\
1609+
16141610
:obj:`otherfunc`
16151611
relationship
16161612
"""
@@ -1636,7 +1632,7 @@ def test_see_also_refs(self):
16361632
.. seealso::
16371633
16381634
:obj:`some`, :obj:`other`, :obj:`funcs`
1639-
\n\
1635+
16401636
:obj:`otherfunc`
16411637
relationship
16421638
"""
@@ -1665,7 +1661,7 @@ def test_see_also_refs(self):
16651661
.. seealso::
16661662
16671663
:obj:`some`, :obj:`MyClass.other`, :func:`funcs`
1668-
\n\
1664+
16691665
:func:`~my_package.otherfunc`
16701666
relationship
16711667
"""

0 commit comments

Comments
 (0)