-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documenting return types using Julia syntax #22804
Comments
Another example to consider """
@__LINE__ -> Int
"""
"""
@__LINE__::Int
"""
|
Currently the arrow is used inconsistently: sometimes to express the return type, sometimes to express the return value (e.g. |
I guess that would be fine, or we could use |
There are also docstrings of the following form where the return value is given a variable name
from Edit: What I'm trying to say is that the syntax proposed in the OP would not work in this case, when giving a name and just not a type to the return value. |
@fredrikekre How about the follwoing ( with """
lufact(A::SparseMatrixCSC)::UmfpackLU = F
Compute the LU factorization of a sparse matrix A.
[...]
""" |
That looks backwards, from the usual syntax where you would type
but that takes focus from the function itself so that's not very nice. |
Listing additional ideas: # for types use :: and return values use =
# opt 1
"""
lufact(A::SparseMatrixCSC) = (F::UmfpackLU)
Compute the LU factorization of a sparse matrix A.
[...]
"""
# opt 2
"""
lufact(A::SparseMatrixCSC)::UmfpackLU = F
Compute the LU factorization of a sparse matrix A.
[...]
"""
# for types use :: and return values use ->
# opt 3
"""
lufact(A::SparseMatrixCSC) -> F::UmfpackLU
Compute the LU factorization of a sparse matrix A.
[...]
"""
# opt 4
"""
lufact(A::SparseMatrixCSC)::UmfpackLU -> F
Compute the LU factorization of a sparse matrix A.
[...]
"""
|
I like |
For option 1 and 3, it's not clear what it would lool like when there are no return value. Also I think a return value is only useful to specify when it's also an argument name (i.e. to document the identity of objects), or at least when it is used in the docstring (but this could otherwise be introduced in the docstring itself when useful, so that the signature is minimal). |
I favour options 3 and 4. But I suspect in many cases the name/description of the returned object could be removed and replaced with a mention in the docstring text. Also note that with |
I prefer using actual julia syntax, as suggested above by @fredrikekre. Indeed I've actually snuck it in once already. I don't think it distracts too much. |
From discussion on slack: Lyndon White [12:33 PM] @oxinaboxThe convention of putting Stefan Karpinski [12:39 PM] @StefanKarpinskithat’s fine when Lyndon White [12:40 PM]using Stefan Karpinski [12:54 PM]that seems like a sensible way to do it Jiahao [12:58 PM] @jiahaoThe Matt Bauman [1:37 PM] @mbaumanI suppose we could use Lyndon White [1:39 PM]It is in a docstring, it is pseudosyntax Matt Bauman [1:57 PM]Oh, your gripe isn’t so much about Michael K. Borregaard [2:03 PM] @mkborregaardI have to say it’s always really confused me to see the anonymous function syntax used in a completely different way Stefan Karpinski [2:11 PM] @StefanKarpinskihistorically, it was because the manual was in Restructured Text for a while David Sanders [3:03 PM] @dpsandersDoes an average user who is looking at the docstring understand what Kristoffer Carlsson [3:04 PM] @KristofferCYou learn it and then you know 😛 Chris de Graaf [3:14 PM] @christopher-dGimo Simon Byrne [3:31 PM] @simonbyrneI would prefer actual Julia syntax, e.g. Fredrik Ekre [3:35 PM] @fredrikekreTake your gripes here: #22804 David Sanders [3:57 PM]It's definitely useful to indicate to the user how the function should actually be called Stefan Karpinski [4:01 PM]that might be confusing for Matlab users who could think that you can actually defined functions that way which you cannot, of course |
Should we do anything about this ? Has the ship sailed (an autoformatter could probably take care of this) |
I was originally in favor of this and still think it's ok when the return type can be clearly and correctly written in Julia syntax, but I tend to prefer using the |
Why not have an explicit |
I agree that using a::Int, b::String = foo(...) might be clearer? I know some folks frown on naming the outputs, but it frankly makes it easier to talk about them meaningfully in the docs. E.g., " |
It looks like Base is using the following convention to document return types
The proposal is to use Julia's return syntax instead, e.g.
related #4902
The text was updated successfully, but these errors were encountered: