# Docstrings attached to signatures

**URL:** https://discourse.julialang.org/t/docstrings-attached-to-signatures/15612
**Category:** Internals & Design
**Created:** [September 28, 2018, 1:32pm UTC](https://discourse.julialang.org/t/docstrings-attached-to-signatures/15612 "2018-09-28T13:32:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)
#### Post date: [September 28, 2018, 1:32pm UTC](https://discourse.julialang.org/t/docstrings-attached-to-signatures/15612/1 "2018-09-28T13:32:09Z")

</div>

As part of [Change signatures that help is showing (revive #25672, fix #20064) by thofma · Pull Request #29102 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/29102) and [https://github.com/JuliaDocs/Documenter.jl/issues/839](https://github.com/JuliaDocs/Documenter.jl/issues/839) I am digging a bit through the docsystem and hit a wall when trying to figure out how docstrings are paired up with signatures. Here is a simple example.

```julia
julia> module Mod 
         """A""" foo(::Int) = nothing
       
         """B""" foo(::Vector{T}) where {T} = nothing
       end

```

Now let’s look at the docstrings attached to the different methods of `Mod.foo`.

```julia
julia> Docs.meta(Mod)[Docs.Binding(Mod, :foo)].order
2-element Array{Type,1}:
 Tuple{Int64}                              
 Union{Tuple{Array{T,1}}, Tuple{T}} where T

```

I understand the first one, but I don’t understand the second one. Is this union intended? I would have thought that the signatures showing up there would be more similar to

```julia
julia> [f.sig for f in methods(Mod.foo)]
2-element Array{Type,1}:
 Tuple{typeof(Main.Mod.foo),Int64}             
 Tuple{typeof(Main.Mod.foo),Array{T,1}} where T

```

I am quite puzzled by this, so any help or pointers in the right direction are appreciated.

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [September 30, 2018, 4:55am UTC](https://discourse.julialang.org/t/docstrings-attached-to-signatures/15612/2 "2018-09-30T04:55:32Z")

</div>

When the function signature is parameterized, the parameters are gathered too:

```julia
julia> module Mod 
           """A""" foo(x::T) where T = nothing
           """B""" foo(::Vector{T}) where {T} = nothing
       end
Main.Mod

julia> Docs.meta(Mod)[Docs.Binding(Mod, :foo)].order
2-element Array{Type,1}:
 Union{Tuple{T}, Tuple{T}} where T         
 Union{Tuple{Array{T,1}}, Tuple{T}} where T

julia> """ a """ foo(x::S, y::T) where {S,T} = nothing;
julia> """ b """ foo(x::S, y::T) where {T,S} = nothing;
julia> """ c """ foo(x::T, y::S) where {T,S} = nothing;
julia> """ d """ foo(x::T, y::S) where {S,T} = nothing;

julia> Docs.meta(Main)[Docs.Binding(Main, :foo)].order
4-element Array{Type,1}:
 Union{Tuple{T}, Tuple{S}, Tuple{S,T}} where T where S
 Union{Tuple{S}, Tuple{T}, Tuple{S,T}} where S where T
 Union{Tuple{S}, Tuple{T}, Tuple{T,S}} where S where T
 Union{Tuple{T}, Tuple{S}, Tuple{T,S}} where T where S

```

---

<div class="post-metadata">

### Author: ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)
#### Post date: [September 30, 2018, 9:11am UTC](https://discourse.julialang.org/t/docstrings-attached-to-signatures/15612/3 "2018-09-30T09:11:48Z")

</div>

Thanks! Apparently the culprit is `Docs.signature!`, see [https://github.com/JuliaLang/julia/issues/29437](https://github.com/JuliaLang/julia/issues/29437).
