Deprecate keyword argument

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

@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.

@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?

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

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