Is there a way to get a function's signatures at run time? I'd like to check the signature before calling that function. Something like:
exp = @sig func
if "kw" ∈ string(exp)
func(kw=value)
end
Is there a way to get a function's signatures at run time? I'd like to check the signature before calling that function. Something like:
exp = @sig func
if "kw" ∈ string(exp)
func(kw=value)
end
In Julia 1.1 The signature can be obtained in the following way:
julia> function test(a::Integer, b::Integer, c::Integer)
end
test (generic function with 2 methods)
julia> function extractSig(x) methods(x).ms[1].sig end
julia> extractSig(test)
Tuple{typeof(test),Integer,Integer,Integer}
If the symbols for the signature is needed the following base function suffices in Julia 1.1 that is
Base.method_argnames(methods(x).ms[1])
It is worth noting that the code above only consider the first definition of the function. There might be more overloaded definitions