Skip to content

Commit 0b3d33b

Browse files
committed
pass cls thru to structure call
1 parent e474b71 commit 0b3d33b

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

flopy4/mf6/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ class WriteError(Exception):
2828
def _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

3434
def _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

4040
def _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

4646
def _write_mf6(component: Component, context=None, **kwargs) -> None:

flopy4/mf6/converter/__init__.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,30 @@ def _make_converter() -> Converter:
4040
COMPONENT_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

0 commit comments

Comments
 (0)