Skip to content

Commit c0c174b

Browse files
committed
wip: unexpected unindent error
1 parent 822065a commit c0c174b

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,6 @@ def _inject_signature( # noqa: C901
741741

742742
if insert_index is not None:
743743

744-
# advance index to the end of paragraph
745-
# nlines = len(lines)
746-
# while insert_index < nlines and (lines[insert_index + 1] == "" or lines[insert_index + 1].startswith(" ")):
747-
# insert_index += 1
748-
749744
if annotation is None:
750745
type_annotation = f":type {arg_name}: "
751746
else:
@@ -756,11 +751,19 @@ def _inject_signature( # noqa: C901
756751
formatted_default = format_default(app, default, annotation is not None)
757752
if formatted_default:
758753
if app.config.typehints_defaults.endswith("after"):
759-
lines[insert_index] += formatted_default
754+
755+
# advance index to the end of the :param: paragraph
756+
nlines = len(lines)
757+
i = insert_index
758+
while i < nlines and (lines[i + 1] == "" or lines[i + 1].startswith(" ")):
759+
i = i + 1
760+
761+
lines[i] += formatted_default
762+
760763
else: # add to last param doc line
761764
type_annotation += formatted_default
762765

763-
lines.insert(insert_index + 1, type_annotation)
766+
lines.insert(insert_index, type_annotation)
764767

765768

766769
@dataclass

tests/test_integration_issue_384.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def dec(val: T) -> T:
5252
bytes
5353
""",
5454
)
55-
def function(x: int = 5, y: int = 10, z: int = 5) -> str: # noqa: ARG001
55+
def function1(x: int, y: int, z: int) -> str: # noqa: ARG001
5656
"""
5757
Function docstring.
5858
@@ -61,12 +61,41 @@ def function(x: int = 5, y: int = 10, z: int = 5) -> str: # noqa: ARG001
6161
:param y: another optional specifier for how to handle complex data types. See
6262
``ivy.func_wrapper.handle_complex_input`` for more detail.
6363
64-
:param y: yet another optional specifier for how to handle complex data types. See
64+
:param z: yet another optional specifier for how to handle complex data types. See
6565
``ivy.func_wrapper.handle_complex_input`` for more detail.
6666
:return: something
6767
:rtype: bytes
6868
"""
6969

70+
@expected(
71+
"""\
72+
mod.function(x=5)
73+
74+
Function docstring.
75+
76+
Parameters:
77+
**x** ("int") -- optional specifier for how to handle complex
78+
data types. See "ivy.func_wrapper.handle_complex_input" for more
79+
detail.
80+
81+
Returns:
82+
something
83+
84+
Return type:
85+
bytes
86+
""",
87+
)
88+
def function(x: int = 5, y: int = 10, z: int = 5) -> str: # noqa: ARG001
89+
"""
90+
Function docstring.
91+
92+
:param x: optional specifier
93+
line 2
94+
95+
:return: something
96+
:rtype: bytes
97+
"""
98+
7099

71100
# Config settings for each test run.
72101
# Config Name: Sphinx Options as Dict.

0 commit comments

Comments
 (0)