Generate doc string with function signature

Hi there,

I think I heard something like this before but I don’t remember. Is there a package/tool that generates and include function signatures in the doc string? E.g.

"""
@sig
Basically, add `x` and `y` together.
"""
add_these(x::Float64, y::Float64) = x + y

turning into something like:

"""
add_these(x::Float64, y::Float64)::Float64

Basically, add `x` and `y` together.
"""
add_these(x::Float64, y::Float64) = x + y
3 Likes

DocStringExtensions is what you’re looking for.

7 Likes

DocStringExtensions works great but it provides a list with signatures from all methods ( using $(SIGNATURES)).

Is there a way to add only the signature of the method being documented?

Not at the moment, but I would be happy to review a PR for that.

1 Like

I saw that DocStringExtensions uses the methods function which brings all signatures. I do not know how to get the signature from the current method. Actually, I do not know how to get a handle for the current method being documented.

I think you can base most of the code on SIGNATURES, except instead of getting all the methods, just use the single one.

If you don’t want to do this, I can make a PR, I wanted this functionality too for a long time.

2 Likes

Please feel free to submit a PR.