Skip to content

Commit 4631c27

Browse files
committed
allow reomval of sym metadata by passing nothing
1 parent e938b66 commit 4631c27

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/metadata.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,17 @@ for md in [:default, :guess, :init, :bounds]
137137
Sets the `$($(QuoteNode(md)))` value for symbol `sym` to `value` in a component model,
138138
or for a symbol referenced by `sni` in a network.
139139
140+
If `value` is `nothing` or `missing`, the metadata is removed.
141+
140142
See also [`has_$($(QuoteNode(md)))`](@ref), [`get_$($(QuoteNode(md)))`](@ref).
141143
"""
142-
$fname_set(c::Comp_or_NW, sym, val) = set_metadata!(c, sym, $(QuoteNode(md)), val)
144+
function $fname_set(c::Comp_or_NW, sym, val)
145+
if !isnothing(val) && !ismissing(val)
146+
set_metadata!(c, sym, $(QuoteNode(md)), val)
147+
else
148+
delete_metadata!(c, sym, $(QuoteNode(md)))
149+
end
150+
end
143151

144152
"""
145153
delete_$($(QuoteNode(md)))!(c::ComponentModel, sym::Symbol)

0 commit comments

Comments
 (0)