Skip to content

Commit

Permalink
feat: extend Base.parentmodule for Model
Browse files Browse the repository at this point in the history
  • Loading branch information
ven-k committed Dec 5, 2023
1 parent d691373 commit 3335751
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct Model{F, S}
end
(m::Model)(args...; kw...) = m.f(args...; kw...)

Base.parentmodule(m::Model) = parentmodule(m.f)

for f in (:connector, :mtkmodel)
isconnector = f == :connector ? true : false
@eval begin
Expand Down
12 changes: 12 additions & 0 deletions test/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,15 @@ end
@test getdefault(component.written_out_for_1.sc) == 2
@test getdefault(component.written_out_for_2.sc) == 3
end

module GetParentModule

using ModelingToolkit

@mtkmodel Component begin end

end

@testset "Parent module of Models" begin
@test parentmodule(GetParentModule.Component) == GetParentModule
end

0 comments on commit 3335751

Please sign in to comment.