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

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-get-keyword-argument-names-of-a-method/20454>\
**Category:** General Usage\
**Created:** [February 4, 2019, 10:48pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-get-keyword-argument-names-of-a-method/20454 "2019-02-04T22:48:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [February 4, 2019, 10:48pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-get-keyword-argument-names-of-a-method/20454/1 "2019-02-04T22:48:18Z")

</div>

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

```julia
f(x; y) = ()

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

```

FWIW, getting the positional argument names could look like,

```julia
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.

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 4, 2019, 11:06pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-get-keyword-argument-names-of-a-method/20454/2 "2019-02-04T23:06:38Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [February 4, 2019, 11:23pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-get-keyword-argument-names-of-a-method/20454/3 "2019-02-04T23:23:28Z")

</div>

Nice, good enough for my purposes, thanks!

---

<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:** [February 5, 2019, 1:15am UTC](https://discourse.julialang.org/t/is-there-a-way-to-get-keyword-argument-names-of-a-method/20454/4 "2019-02-05T01:15:32Z")

</div>

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