Getting doc string from function in composite type?


#1

What’s the trick for getting the docstring of the function stored in a composite type’s field?

type MyType                                    
   f::Function
end

julia> s = MyType(sin)                                    
MyType(sin)

julia> s.f                                                
sin (generic function with 10 methods)

julia> @doc sin                                            
sin(x)

Compute sine of x, where x is in radians.

julia> @doc(s.f)                             
ERROR: MethodError: no method matching Base.Docs.Binding(::MyType, ::Symbol)
Closest candidates are:
Base.Docs.Binding(::Module, ::Symbol) at docs/bindings.jl:12

julia> @doc s.f                                     
ERROR: MethodError: no method matching Base.Docs.Binding(::MyType, ::Symbol)
Closest candidates are:
  Base.Docs.Binding(::Module, ::Symbol) at docs/bindings.jl:12

julia> @doc (s.f)                             
ERROR: MethodError: no method matching Base.Docs.Binding(::MyType, ::Symbol)
Closest candidates are:
  Base.Docs.Binding(::Module, ::Symbol) at docs/bindings.jl:12

#2
julia> Base.Docs.doc(s.f)
  sin(x)

  Compute sine of x, where x is in radians.

#3

These seem to work:

g = s.f
@doc g

or

Docs.doc(s.f)

#4

Thanks!