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

Some docstrings always show up (but they should not) #20064

Open
thofma opened this issue Jan 16, 2017 · 6 comments
Open

Some docstrings always show up (but they should not) #20064

thofma opened this issue Jan 16, 2017 · 6 comments
Labels
docsystem The documentation building system

Comments

@thofma
Copy link
Contributor

thofma commented Jan 16, 2017

There is a docstring for Base.length, which shows up for any input type (but it should not). This makes it impossible very hard to automatically build documentations in case one wants to document a custom length function.

julia> type A end

julia> doc"""asdasds""" function Base.length(a::A) end
Base.length

help?> length(A())
  length(collection) -> Integer

  For ordered, indexable collections, the maximum index i for which getindex(collection, i) is valid.
  For unordered collections, the number of elements.

  asdasds

Happens also for builtin types

@tkelman tkelman added the docsystem The documentation building system label Jan 16, 2017
@thofma
Copy link
Contributor Author

thofma commented Jan 20, 2018

I just checked on the lastest master. The docstring for length("string") does not show the collection doc string anymore. But it still happens for user defined types, in particular for types in the standard library:

julia> using Dates

help?> Date() + Time()
  +(x, y...)

  Addition operator. x+y+z+... calls this function with all arguments, i.e. +(x, y, z, ...).

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> 1 + 20 + 4
  25
  
  julia> +(1, 20, 4)
  25

  dt::Date + t::Time -> DateTime

  The addition of a Date with a Time produces a DateTime. The hour, minute, second, and millisecond parts of the Time are used along with the year, month, and day of the Date to create the new
  DateTime. Non-zero microseconds or nanoseconds in the Time type will result in an InexactError being thrown.
julia> versioninfo()
Julia Version 0.7.0-DEV.3478
Commit 9028130* (2018-01-20 09:44 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)
Environment:

@nalimilan
Copy link
Member

What's the problem with the output you show?

@thofma
Copy link
Contributor Author

thofma commented Jan 21, 2018

The problem is that you get two concetanated docstrings: The generic one for +(x,y,...) and the one for +(::Date, ::Time). This should not happend. length(::String) is an example where it does not happen:

help?> length("a")
  length(s::AbstractString) -> Int
  length(s::AbstractString, i::Integer, j::Integer) -> Int

  The number of characters in string s from indices i through j. This is computed as the number of code unit indices from i to j which are valid character indices. Without only a single string
  argument, this computes the number of characters in the entire string. With i and j arguments it computes the number of indices between i and j inclusive that are valid indices in the string
  s. In addition to in-bounds values, i may take the out-of-bounds value ncodeunits(s) + 1 and j may take the out-of-bounds value 0.

  See also: isvalid, ncodeunits, endof, thisind, nextind, prevind

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> length("jμΛIα")
  5

Here you don't get the docstring for the length(::Any) fallback.

Because you get also the docstring for the Base types, this makes it impossible to write nice looking documentations using Documenter: Whenever you include the docstring for say + on user defined types, you also get the generic docstring. So if I document + for five different times, I automatically include five times the following string:

  +(x, y...)

  Addition operator. x+y+z+... calls this function with all arguments, i.e. +(x, y, z, ...).

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> 1 + 20 + 4
  25
  
  julia> +(1, 20, 4)
  25

I think this is a problem. You don't see this in the julia manual, because for some reason (https://docs.julialang.org/en/latest/stdlib/Dates/#stdlib-dates-1) does not include the documentation for +(::Date, ::Time).

@KristofferC
Copy link
Member

KristofferC commented Jan 21, 2018

Here you don't get the docstring for the length(::Any) fallback.

There are no length(::Any) fallbacks.

Because you get also the docstring for the Base types

You get the docstrings for everything that matches your query so it doesn't really have anything to do with base types. However, showing only the more specific methods probably makes sense.

On 0.6, we had:

help?> Date() + Time()
  dt::Date + t::Time -> DateTime

  The addition of a Date with a Time produces a DateTime. The hour, minute, second, and millisecond parts of the Time are used along with the year, month, and day of the Date
  to create the new DateTime. Non-zero microseconds or nanoseconds in the Time type will result in an InexactError being thrown.

so this looks like a regression?

@KristofferC
Copy link
Member

Ok, the difference in 0.6 and 0.7 is due to that on 0.6, the +(x, y...) docstring was attached to the symbol + while in 0.7 it is attached to the actual +(x, y...) function.

@KristofferC
Copy link
Member

I elaborated a bit in #25672. @thofma

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

4 participants