Skip to content

Commit f775072

Browse files
committed
comforming to pre-commit
1 parent c0c174b commit f775072

File tree

2 files changed

+38
-46
lines changed

2 files changed

+38
-46
lines changed

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -750,20 +750,31 @@ def _inject_signature( # noqa: C901
750750
if app.config.typehints_defaults:
751751
formatted_default = format_default(app, default, annotation is not None)
752752
if formatted_default:
753-
if app.config.typehints_defaults.endswith("after"):
753+
type_annotation = _append_default(app, lines, insert_index, type_annotation, formatted_default)
754754

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
755+
lines.insert(insert_index, type_annotation)
762756

763-
else: # add to last param doc line
764-
type_annotation += formatted_default
765757

766-
lines.insert(insert_index, type_annotation)
758+
def _append_default(
759+
app: list[str], lines: Sphinx, insert_index: int, type_annotation: str, formatted_default: str
760+
) -> str:
761+
if app.config.typehints_defaults.endswith("after"):
762+
# advance the index to the end of the :param: paragraphs
763+
# (terminated by a line with no indentation)
764+
# append default to the last nonempty line
765+
nlines = len(lines)
766+
i = insert_index + 1
767+
j = insert_index # last nonempty line
768+
while i < nlines and (not lines[i] or lines[i].startswith(" ")):
769+
if lines[i]:
770+
j = i
771+
i += 1
772+
lines[j] += formatted_default
773+
774+
else: # add to last param doc line
775+
type_annotation += formatted_default
776+
777+
return type_annotation
767778

768779

769780
@dataclass

tests/test_integration_issue_384.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,61 +36,42 @@ def dec(val: T) -> T:
3636

3737
@expected(
3838
"""\
39-
mod.function(x=5)
39+
mod.function(x=5, y=10, z=15)
4040
4141
Function docstring.
4242
4343
Parameters:
44-
**x** ("int") -- optional specifier for how to handle complex
45-
data types. See "ivy.func_wrapper.handle_complex_input" for more
46-
detail.
47-
48-
Returns:
49-
something
50-
51-
Return type:
52-
bytes
53-
""",
54-
)
55-
def function1(x: int, y: int, z: int) -> str: # noqa: ARG001
56-
"""
57-
Function docstring.
44+
* **x** ("int") -- optional specifier line 2 (default: "5")
5845
59-
:param x: optional specifier for how to handle complex data types. See
60-
``ivy.func_wrapper.handle_complex_input`` for more detail.
61-
:param y: another optional specifier for how to handle complex data types. See
62-
``ivy.func_wrapper.handle_complex_input`` for more detail.
46+
* **y** ("int") --
6347
64-
:param z: yet another optional specifier for how to handle complex data types. See
65-
``ivy.func_wrapper.handle_complex_input`` for more detail.
66-
:return: something
67-
:rtype: bytes
68-
"""
48+
another optional line 4
6949
70-
@expected(
71-
"""\
72-
mod.function(x=5)
50+
second paragraph for y (default: "10")
7351
74-
Function docstring.
52+
* **z** ("int") -- yet another optional s line 6 (default: "15")
7553
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-
8154
Returns:
8255
something
8356
8457
Return type:
8558
bytes
59+
8660
""",
8761
)
88-
def function(x: int = 5, y: int = 10, z: int = 5) -> str: # noqa: ARG001
62+
def function(x: int = 5, y: int = 10, z: int = 15) -> str: # noqa: ARG001
8963
"""
9064
Function docstring.
9165
92-
:param x: optional specifier
66+
:param x: optional specifier
9367
line 2
68+
:param y: another optional
69+
line 4
70+
71+
second paragraph for y
72+
73+
:param z: yet another optional s
74+
line 6
9475
9576
:return: something
9677
:rtype: bytes

0 commit comments

Comments
 (0)