Skip to content

Commit 99a7647

Browse files
authored
Document how return types and return values should be used in docstrign signature lines (#57583)
1 parent c75cf3f commit 99a7647

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

doc/src/manual/documentation.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,35 @@ As in the example above, we recommend following some simple conventions when wri
8181
accepts many keyword arguments, only include a `<keyword arguments>` placeholder in the signature
8282
(i.e. `f(x; <keyword arguments>)`), and give the complete list under an `# Arguments` section
8383
(see point 4 below).
84+
85+
Use this style to document the return type or give the return value a name:
86+
87+
```julia
88+
# Naming the return value or its type is not necessary (this is the most common case)
89+
"""
90+
sum(itr; [init])
91+
92+
...
93+
"""
94+
95+
# The return type is easily documented and critical to the semantics of this function
96+
"""
97+
vec(x::AbstractArray)::AbstractVector
98+
99+
...
100+
"""
101+
102+
# Naming and/or destructuring the return value clarifies the semantics of this function
103+
"""
104+
splitdir(path::AbstractString) -> (dir::AbstractString, file::AbstractString)
105+
...
106+
"""
107+
```
108+
When included, a return type should be written after the signature, separated by `::`,
109+
while a named return value should be separated by ` -> `, with a space on both sides.
110+
Return types and return values should be valid Julia expressions when possible.
111+
Macro docstring signatures that annotate return types or return values should use
112+
parentheses to clarify where the macro arguments end and return type or return value begins.
84113
2. Include a single one-line sentence describing what the function does or what the object represents
85114
after the simplified signature block. If needed, provide more details in a second paragraph, after
86115
a blank line.

0 commit comments

Comments
 (0)