# Passing keyword arguments through a thin wrapper without explicitly writing them out

**URL:** <https://discourse.julialang.org/t/passing-keyword-arguments-through-a-thin-wrapper-without-explicitly-writing-them-out/8173>\
**Category:** General Usage\
**Created:** [January 5, 2018, 8:18am UTC](https://discourse.julialang.org/t/passing-keyword-arguments-through-a-thin-wrapper-without-explicitly-writing-them-out/8173 "2018-01-05T08:18:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [January 5, 2018, 8:18am UTC](https://discourse.julialang.org/t/passing-keyword-arguments-through-a-thin-wrapper-without-explicitly-writing-them-out/8173/1 "2018-01-05T08:18:30Z")

</div>

I wonder if there is a way to pass on keyword arguments through a thin wrapper without having to explicitly type the keyword arguments, something like the following Python code. Splatting doesn’t seem to work, nor does passing a dictionary, anything other obvious way I missed? Will this change with named tuples in v1.0?

```python
>>> def f(**kwargs):
... return kwargs
...
>>> f(a = 1, b = 2, c = 3)
{'a': 1, 'c': 3, 'b': 2}
>>> type(f(a = 1, b = 2, c = 3))
<type 'dict'>
>>> def g(**kwargs):
... return f(**kwargs)
...
>>> g(a = 1, b = 2, c = 3)
{'a': 1, 'c': 3, 'b': 2}

```

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [January 5, 2018, 8:25am UTC](https://discourse.julialang.org/t/passing-keyword-arguments-through-a-thin-wrapper-without-explicitly-writing-them-out/8173/2 "2018-01-05T08:25:17Z")

</div>

This is what I missed 😅

```julia
julia> f(;kwargs...) = Dict(kwargs)
f (generic function with 1 method)

julia> g(;kwargs...) = f(;kwargs...)
g (generic function with 1 method)

julia> g(a = 1, b = 2, c = 3)
Dict{Symbol,Int64} with 3 entries:
  :a => 1
  :b => 2
  :c => 3

```

Thanks to @mkborregaard in [How to collect keyword arguments in a Dict? - #5 by mkborregaard](https://discourse.julialang.org/t/how-to-collect-keyword-arguments-in-a-dict/6693/5)

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [July 24, 2018, 11:54pm UTC](https://discourse.julialang.org/t/passing-keyword-arguments-through-a-thin-wrapper-without-explicitly-writing-them-out/8173/3 "2018-07-24T23:54:44Z")

</div>

Why do you have to recast the `kwargs` as a dictionary though?

It seems kind of weird you need an intermediate function that is just calling a `Dict` constructor?

* * *

The way I work around it is with:

```julia
default_kwargs = Dict()
f(kwargs=default_kwargs)

```

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [July 25, 2018, 6:47pm UTC](https://discourse.julialang.org/t/passing-keyword-arguments-through-a-thin-wrapper-without-explicitly-writing-them-out/8173/4 "2018-07-25T18:47:39Z")

</div>

> [@djsegal](#):
>
> Why do you have to recast the `kwargs` as a dictionary though?

I don’t remember! It was me answering another question or some exercise or something.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 25, 2018, 6:58pm UTC](https://discourse.julialang.org/t/passing-keyword-arguments-through-a-thin-wrapper-without-explicitly-writing-them-out/8173/5 "2018-07-25T18:58:15Z")

</div>

Isn’t that just to show that the kwargs got passed through.
