# How to get a functions keyword argument types?

**URL:** <https://discourse.julialang.org/t/how-to-get-a-functions-keyword-argument-types/78781>\
**Category:** General Usage\
**Tags:** functions\
**Created:** [March 31, 2022, 2:57am UTC](https://discourse.julialang.org/t/how-to-get-a-functions-keyword-argument-types/78781 "2022-03-31T02:57:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![onetonfoot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/onetonfoot/32/2697_2.png) [@onetonfoot](https://discourse.julialang.org/u/onetonfoot)\
**Post date:** [March 31, 2022, 2:57am UTC](https://discourse.julialang.org/t/how-to-get-a-functions-keyword-argument-types/78781/1 "2022-03-31T02:57:22Z")

</div>

How can I get the types for the keyword arguments of a function? For example, with normal arguments I can use

```julia
f(x::Int) = x
methods(f)[1].sig
#Tuple{typeof(f), Int64}

```

I’m looking for something along the lines of

```julia
g(x::Int; y= 10 ) = x + y
magical_function(g) 
# (y = Int64,)

```

---

<div class="post-metadata">

**Author:** ![onetonfoot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/onetonfoot/32/2697_2.png) [@onetonfoot](https://discourse.julialang.org/u/onetonfoot)\
**Post date:** [April 7, 2022, 12:59pm UTC](https://discourse.julialang.org/t/how-to-get-a-functions-keyword-argument-types/78781/2 "2022-04-07T12:59:16Z")

</div>

I figured something out

```julia
using CodeTracking, ExprManipulation, ExprTools
using Base.Meta

function fn_expr(fn)
	ms = methods(fn)
	m = ms[1]
	types = tuple(m.sig.types[2:end]...)
	Meta.parse(code_string(fn, types))
end

function fn_kwargs(fn)
	expr = fn_expr(fn)
	def = splitdef(expr)
	d = Dict()
	m_expr = MExpr(:kw, Capture(:var), Capture(:expr))
	for i in def[:kwargs]
		m = match(m_expr, i)
		d[m.var] = eval(m.expr)
	end
	d
end

```
