Is there a nice way of allowing a function to ignore unsupported keyword arguments?
fopts = [:kw1]
opts = Dict(:kw1=>:symb1, :kw2=>:symb2)
function f(; kw1 = :symb)
return kw1
end
f(;opts...)
will throw a METHOD ERROR
I could wrap it in something like this, but then I still need to know which kwargs f
will support?
function f2(fopts; kwargs)
f(; Dict(key=>get(opts, key, 0) for key in fopts)...)
end
Am I missing a way around this. Not that fussed if there is a performance penalty as I imagine their may need to be some kind of look up. Is there a good way of interrogating what kwargs f
accepts programatically?
f(x; kwargs...) = (kwargs = Dict(kwargs); ...)
and just use the keywords your function should support and ignore the rest.fopts=methods(methods(f).mt.kwsorter).mt.defs.func.lambda_template.slotnames
. i guess there must be a clean way to do this.getkwargs
function...