Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/utils/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,18 @@ julia> strip_module_name(VariableReserve{PowerSystems.ReserveUp})
# Fall back to string method for Union types
return :(strip_module_name(string(T)))
end
name = string(nameof(T))
if isempty(T.parameters)
# A partially-applied parameterized type (e.g. `ReserveDemandCurve{ReserveUp}` when the
# type carries a further free parameter such as a unit system) is a `UnionAll` and has
# no `.parameters`. Unwrap it and drop the free `TypeVar`s, keeping the bound parameters
# so the stripped name stays unique on those (e.g. "ReserveDemandCurve{ReserveUp}").
base = T isa UnionAll ? Base.unwrap_unionall(T) : T
name = string(nameof(base))
params = filter(p -> !(p isa TypeVar), collect(base.parameters))
if isempty(params)
Comment on lines +194 to +197

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a test but we couldn't test if it actually removed a module name without adding a whole submodule.

return name
else # I believe there's only 2 parameters, so slightly overkill.
param_names = join([string(nameof(p)) for p in T.parameters], ", ")
param_names =
join([p isa Type ? string(nameof(p)) : string(p) for p in params], ", ")
return name * "{" * param_names * "}"
end
end
Expand Down
Loading