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

Function documentation ignored when not at toplevel #14962

Open
nalimilan opened this issue Feb 6, 2016 · 11 comments
Open

Function documentation ignored when not at toplevel #14962

nalimilan opened this issue Feb 6, 2016 · 11 comments
Labels
docsystem The documentation building system

Comments

@nalimilan
Copy link
Member

If you save the following code to a file and include() it, neither ?f nor ?g will print any documentation. Removing the if fixes the problem. This is annoying when only adding a function depending on the Julia version, notably when extending a Base function which may not exist in older releases.

if false
    """
    Do something funny.
    """
    f(x) = 1
else
    """
    Do something sad.
    """
    g(x) = 1
end
@nalimilan nalimilan added the docsystem The documentation building system label Feb 6, 2016
@yuyichao
Copy link
Contributor

yuyichao commented Feb 6, 2016

I thought this was intentional. The @doc "..." -> should still work?

@nalimilan
Copy link
Member Author

Indeed it does. Maybe that's intentional and there are implications I'm not seeing, but that's certainly not user-friendly.

nalimilan added a commit to JuliaStrings/StringEncodings.jl that referenced this issue Feb 6, 2016
@tlnagy
Copy link
Contributor

tlnagy commented Mar 1, 2016

What was the original intent here?

@kshyatt
Copy link
Contributor

kshyatt commented Jan 26, 2017

@MichaelHatherly is this still a problem?

@MichaelHatherly
Copy link
Member

Presumably covered by #20198?

@omus
Copy link
Member

omus commented Aug 28, 2017

Still currently an issue. Can be seen in the wild with the LibGit2.Consts.GIT_CONFIG docstring.

@omus
Copy link
Member

omus commented Aug 28, 2017

Documentation also states that docstrings in ifs should work:

if condition()
    "..."
    f(x) = x
end

@bramtayl
Copy link
Contributor

Yeah I wrote those docs and I was wrong, both about if and let blocks... Sorry...

@omus
Copy link
Member

omus commented Aug 29, 2017

Not a big deal. I'm not sure if this issue is going to be addressed but we should update the documentation. The working syntax is:

if true
    @doc """
    ...
    """ ->
    f(x) = x
end

@LilithHafner
Copy link
Member

LilithHafner commented May 14, 2023

I support inserting @doc implicitly in these cases. An example in the wild is a reinterpret docstring

global reinterpret
"""
reinterpret(T::DataType, A::AbstractArray)
Construct a view of the array with the same binary data as the given
array, but with `T` as element type.
This function also works on "lazy" array whose elements are not computed until they are explicitly retrieved.
For instance, `reinterpret` on the range `1:6` works similarly as on the dense vector `collect(1:6)`:
```jldoctest
julia> reinterpret(Float32, UInt32[1 2 3 4 5])
1×5 reinterpret(Float32, ::Matrix{UInt32}):
1.0f-45 3.0f-45 4.0f-45 6.0f-45 7.0f-45
julia> reinterpret(Complex{Int}, 1:6)
3-element reinterpret(Complex{$Int}, ::UnitRange{$Int}):
1 + 2im
3 + 4im
5 + 6im
```
"""
function reinterpret(::Type{T}, a::A) where {T,N,S,A<:AbstractArray{S, N}}

@LilithHafner LilithHafner changed the title Function documentation ignored when placed under conditional Function documentation ignored when not at toplevel May 14, 2023
@LilithHafner
Copy link
Member

if true
    begin
        """
        ...
        """
        f(x) = x
    end
end

works :P

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

8 participants