# Is there any elegant julian way how to do what python could do with decorator?

**URL:** <https://discourse.julialang.org/t/is-there-any-elegant-julian-way-how-to-do-what-python-could-do-with-decorator/8118>\
**Category:** General Usage\
**Created:** [January 2, 2018, 11:48pm UTC](https://discourse.julialang.org/t/is-there-any-elegant-julian-way-how-to-do-what-python-could-do-with-decorator/8118 "2018-01-02T23:48:32Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [January 3, 2018, 2:48pm UTC](https://discourse.julialang.org/t/is-there-any-elegant-julian-way-how-to-do-what-python-could-do-with-decorator/8118/21 "2018-01-03T14:48:53Z")

</div>

> [@Tamas\_Papp](#):
>
> > [@Liso](#):
> >
> > Are you proposing higher priority to old keyword than to new one?
> 
> I don’t understand what you mean here.

I meant this (thickness is set to 1 but result is 2):

```julia
julia> plo(1,2; thickness=1, size = 2)
       ┌ Warning: `warn()` is deprecated, use `@warn` instead.
        ...
        WARNING: size is deprecated, use thickness
thickness is 2

```

> [@Tamas\_Papp](#):
>
> … suggested because it seemed that you needed help with it.

Really thanks for your intention! 🙂

> [@Tamas\_Papp](#):
>
> Finally, if you are concerned about sentinel values, you can capture all keyword arguments in eg args… and examine them as is.

I repeat that this is OP’s problem not mine, but it bring necessity to deal with default values in body. Which brings additional work to write good doc-string. And avoid to see (new keyword) parameters in tab-completer.

**edit** : my mistake (I am surprised a little) → nor tab-completer nor help nor `methods` show default values…

---

<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 3, 2018, 9:33pm UTC](https://discourse.julialang.org/t/is-there-any-elegant-julian-way-how-to-do-what-python-could-do-with-decorator/8118/22 "2018-01-03T21:33:12Z")

</div>

I know this is not your question, but here is another trick anyways!

```julia
julia> dep_kwargs = Dict(:size => :thickness);

julia> _plo(a, b; thickness=1) = 2;

julia> function plo(a, b; kwargs...)
          real_kwargs = Dict{Symbol, Any}()
          for (s, v) in kwargs
              if haskey(dep_kwargs, s)
                  warn("$(s) is deprecated use $(dep_kwargs[s]) instead!")
                  real_kwargs[dep_kwargs[s]] = v
              else
                  real_kwargs[s] = v
              end
          end
          return _plo(a, b, thickness=real_kwargs[:thickness])
       end
plo (generic function with 1 method)

julia> plo(1, 2, size=2)
WARNING: size is deprecated use thickness instead!
2

julia> plo(1, 2, thickness=2)
2

```

[Previous page](https://discourse.julialang.org/t/is-there-any-elegant-julian-way-how-to-do-what-python-could-do-with-decorator/8118.md?page=1)
