File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,19 +28,19 @@ class WriteError(Exception):
2828def _load_mf6 (cls , path : Path ) -> Component :
2929 """Load MF6 format file into a component instance."""
3030 with open (path , "r" ) as fp :
31- return structure (load_mf6 (fp ), path )
31+ return structure (load_mf6 (fp ), path , component_type = cls )
3232
3333
3434def _load_json (cls , path : Path ) -> Component :
3535 """Load JSON format file into a component instance."""
3636 with open (path , "r" ) as fp :
37- return structure (load_json (fp ), path )
37+ return structure (load_json (fp ), path , component_type = cls )
3838
3939
4040def _load_toml (cls , path : Path ) -> Component :
4141 """Load TOML format file into a component instance."""
4242 with open (path , "rb" ) as fp :
43- return structure (load_toml (fp ), path )
43+ return structure (load_toml (fp ), path , component_type = cls )
4444
4545
4646def _write_mf6 (component : Component , context = None , ** kwargs ) -> None :
Original file line number Diff line number Diff line change @@ -40,8 +40,30 @@ def _make_converter() -> Converter:
4040COMPONENT_CONVERTER = _make_converter ()
4141
4242
43- def structure (data : dict [str , Any ], path : Path ) -> Component :
44- component = COMPONENT_CONVERTER .structure (data , Component )
43+ def structure (
44+ data : dict [str , Any ], path : Path , component_type : type [Component ] | None = None
45+ ) -> Component :
46+ """
47+ Structure parsed data into a Component instance.
48+
49+ Parameters
50+ ----------
51+ data : dict
52+ Parsed component data
53+ path : Path
54+ Path to the component file (for setting workspace/filename)
55+ component_type : type[Component], optional
56+ Concrete component class to instantiate. If not provided, uses Component base class.
57+
58+ Returns
59+ -------
60+ Component
61+ Structured component instance
62+ """
63+ # Use provided type or fall back to Component base class
64+ target_type = component_type if component_type is not None else Component
65+
66+ component = COMPONENT_CONVERTER .structure (data , target_type )
4567 if isinstance (component , Context ):
4668 component .workspace = path .parent
4769 component .filename = path .name
You can’t perform that action at this time.
0 commit comments