Skip to content

strip_module_name: handle UnionAll component types#583

Merged
jd-lara merged 1 commit into
IS4from
ac/union-all-keys
Jun 3, 2026
Merged

strip_module_name: handle UnionAll component types#583
jd-lara merged 1 commit into
IS4from
ac/union-all-keys

Conversation

@acostarelli

Copy link
Copy Markdown
Member

PSY6 parameterized some component families on a unit system (e.g. ReserveDemandCurve{ReserveUp} is now ReserveDemandCurve{ReserveUp, U} where U), making the partially-applied type a UnionAll. The @generated Type method read T.parameters, which only exists on DataType, so it threw a FieldError on these types. Unwrap the UnionAll and drop the free TypeVars, keeping the bound parameters so the stripped name stays unique (e.g. "ReserveDemandCurve{ReserveUp}").

This lets downstream consumers (IOM container-key encoding) drop their local UnionAll workaround.

PSY6 parameterized some component families on a unit system (e.g.
ReserveDemandCurve{ReserveUp} is now ReserveDemandCurve{ReserveUp, U} where U),
making the partially-applied type a UnionAll. The @generated Type method read
T.parameters, which only exists on DataType, so it threw a FieldError on these
types. Unwrap the UnionAll and drop the free TypeVars, keeping the bound
parameters so the stripped name stays unique (e.g. "ReserveDemandCurve{ReserveUp}").

This lets downstream consumers (IOM container-key encoding) drop their local
UnionAll workaround.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request updates strip_module_name(::Type) to correctly handle partially-applied parametric component types that are represented as UnionAll (e.g., when a component family adds a free type parameter like a unit system), preventing FieldError from accessing .parameters on non-DataType types. This supports downstream consumers that rely on stable, unique, module-stripped type strings (e.g., container-key encoding).

Changes:

  • Unwrap UnionAll types before inspecting parameters and drop free TypeVar parameters while keeping bound parameters for uniqueness.
  • Improve parameter stringification to handle non-Type parameters (e.g., value parameters) without error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/utils.jl
params = filter(p -> !(p isa TypeVar), collect(base.parameters))
if isempty(params)
return name
else # I believe there's only 2 parameters, so slightly overkill.
Comment thread src/utils/utils.jl
Comment on lines +194 to +197
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)

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.

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.51%. Comparing base (78217a7) to head (7558864).
⚠️ Report is 3 commits behind head on IS4.

Files with missing lines Patch % Lines
src/utils/utils.jl 80.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##              IS4     #583   +/-   ##
=======================================
  Coverage   83.50%   83.51%           
=======================================
  Files          74       74           
  Lines        6264     6266    +2     
=======================================
+ Hits         5231     5233    +2     
  Misses       1033     1033           
Flag Coverage Δ
unittests 83.51% <80.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/utils/utils.jl 66.56% <80.00%> (+0.19%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@acostarelli acostarelli marked this pull request as draft June 2, 2026 15:46
@acostarelli acostarelli marked this pull request as ready for review June 2, 2026 17:47
@jd-lara jd-lara merged commit 1c69410 into IS4 Jun 3, 2026
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants