# Deprecate keyword argument

**URL:** https://discourse.julialang.org/t/deprecate-keyword-argument/33740
**Category:** New to Julia
**Tags:** question
**Created:** [January 24, 2020, 12:19pm UTC](https://discourse.julialang.org/t/deprecate-keyword-argument/33740 "2020-01-24T12:19:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)
#### Post date: [January 24, 2020, 12:19pm UTC](https://discourse.julialang.org/t/deprecate-keyword-argument/33740/1 "2020-01-24T12:19:16Z")

</div>

I want to deprecate a renamed keyword argument e.g. like this

```julia
@deprecate foo(;a1=1, a2=2) foo(;b1=1, a2=2)
foo(a1=2, a2=3)

```

> Warning: `foo(; a1=1, a2=2)` is deprecated, use `foo(; b1=1, a2=2)` instead.

But I dont want to specify the default values.

```julia
@deprecate foo(;a1, a2) foo(;b1, a2)

```

> ERROR: syntax: invalid keyword argument syntax “b1”

but it seems to not work. Is there an error?

Also, I want to not state all keyword arguments. Only those that did change. Is this possible?

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [January 24, 2020, 2:07pm UTC](https://discourse.julialang.org/t/deprecate-keyword-argument/33740/2 "2020-01-24T14:07:19Z")

</div>

I think this is not really possible. You probably need to do something cumbersome like:

```julia
function foo(;a2=2, kw...)
    if haskey(kw, :a1)
        Base.depwarn("keyword argument a1 is now b1", :foo)
        b1 = kw[:a1]
    else
        b1 = get(kw, :b1, 1)
    end
    # the new foo
end

```

---

<div class="post-metadata">

### Author: ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)
#### Post date: [June 22, 2023, 7:58pm UTC](https://discourse.julialang.org/t/deprecate-keyword-argument/33740/3 "2023-06-22T19:58:04Z")

</div>

I just made a package for doing this here: [GitHub - MilesCranmer/DeprecateKeywords.jl: Macro for deprecating keyword parameters](https://github.com/MilesCranmer/DeprecateKeywords.jl)

Described in this thread: [Standard way to deprecate a keyword argument](https://discourse.julialang.org/t/standard-way-to-deprecate-a-keyword-argument/100534)

```julia
using DeprecateKeywords

@deprecate_kws function foo(;
    new_kw1=2,
    new_kw2=3,
    @deprecate(old_kw1, new_kw1),
    @deprecate(old_kw2, new_kw2)
)
    new_kw1 + new_kw2
end

```
