Skip to content
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

Docstrings attached to multiple methods are printed multiple times #32045

Open
sostock opened this issue May 16, 2019 · 4 comments
Open

Docstrings attached to multiple methods are printed multiple times #32045

sostock opened this issue May 16, 2019 · 4 comments
Labels
docsystem The documentation building system

Comments

@sostock
Copy link
Contributor

sostock commented May 16, 2019

When attaching one docstring to two or more methods of the same function, the docstring is shown multiple times when querying the generic function:

julia> begin
           function f end
           
           """
               f([T], x)
           """
           f(::Type, ::Integer), f(::Integer)
       end;

help?> f
search: f fd for fma fld fld1 fill fdio frexp foldr foldl flush floor float first

  f([T], x)

  ───────────────────────────────────────────────────────────────────────────────

  f([T], x)

The easiest fix would probably be to remove duplicates from the list of docstrings that match a query before printing them.

@fredrikekre
Copy link
Member

I feel like this is the behavior we want. In your case it seems better to attach the docstring to the generic function instead of two methods, since the docstring is written to apply to both.

@fredrikekre fredrikekre added the docsystem The documentation building system label May 16, 2019
@sostock
Copy link
Contributor Author

sostock commented May 16, 2019

If this is the desired behavior, then I guess I will find another solution. FYI, I’m hesitant to write a docstring for the generic function, because I still want to document different behavior for different types of x, which I feel could get messy with a single docstring:

f(T::Type, x; kwargs...) = T(f(x; kwargs...))
f(x::Integer) = x+x
f(x::String; add1=false) = f(length(x)) + add1

"""
    f([T], x::Integer)

do something for integers
"""
f(::Type, ::Integer), f(::Integer)

"""
    f([T], x::String; add1=false)

do something different for strings, with an optional keyword argument
"""
f(::Type, ::String; kwargs...), f(::String; kwargs...)

@sostock
Copy link
Contributor Author

sostock commented May 16, 2019

However, I don’t see any good reason for the current behavior other than saving the computational time of removing duplicates after collecting the relevant docstrings. (IMO, showing the same docstring multiple times does not add value.)

@omus
Copy link
Member

omus commented May 21, 2019

I'll note you can get a more specific docstring by including type information:

help?> f(::Integer)
  f([T], x::Integer)

  do something for integers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docsystem The documentation building system
Projects
None yet
Development

No branches or pull requests

3 participants