Wrapping kw-based Parameters.jl constructor, for deprecation

Ken_Williams
Thu, 21 Nov 2024 19:26:29 +0000
General Usage

I have a config object like this:

using Parameters

@with_kw mutable struct Config
    "Param 1"
    param1::Float64

    # ... several other items ...

    "Whether to iterate randomly."
    use_random::Bool = false
end

And now I need to modify it like so, to enable more than 2 strategies:

@with_kw mutable struct Config
    "Param 1"
    param1::Float64

    # ... several other items ...

    "Strategy for iteration, one of 'random' or 'baseline'."
    iter_strategy::String = "random"
end

But this is a breaking change to its definition, so I want to give some deprecation help to the user.

Is there some way I can intercept existing calls to the keyword-based constructor generated by @with_kw, changing a use_random setting to the appropriate iter_strategy value, and issuing a warning that the caller should change their code? Existing callers would have code like Config(param1=1.1, use_random=true) or similar.

Thanks.

5 posts - 2 participants