Is there a way to get keyword argument names of a method?


I’m looking for a function which would work in the following way:

f(x; y) = ()

get_kwarg_names(first(methods(f))) # would return [:y]

FWIW, getting the positional argument names could look like,

get_arg_names(m::Method) = first.(Base.arg_decl_parts(m)[2][2:end])

but I can’t figure out where the kwarg names are stored or even if I can get at them from Julia? Thanks for any tips.


The following works, but perhaps there’s a cleaner way?

julia> Base.kwarg_decl(first(methods(f)), typeof(methods(f).mt.kwsorter))
1-element Array{Any,1}:


Nice, good enough for my purposes, thanks!


What would be the similar way to get [[args], [kwargs]]? (arg names, kwarg names)