Skip to content

Commit 75e82ef

Browse files
authored
use Dfn.from_dict (#194)
1 parent 9a5ec67 commit 75e82ef

File tree

5 files changed

+176
-234
lines changed

5 files changed

+176
-234
lines changed

flopy4/mf6/component.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from packaging.version import Version
1010
from xattree import xattree
1111

12-
from flopy4.mf6.constants import FILL_DNODATA
12+
from flopy4.mf6.constants import FILL_DNODATA, MF6
1313
from flopy4.mf6.spec import field, fields_dict, to_field
1414
from flopy4.uio import IO, Loader, Writer
1515

@@ -84,9 +84,8 @@ class Component(ABC, MutableMapping):
8484
_load = IO(Loader) # type: ignore
8585
_write = IO(Writer) # type: ignore
8686

87-
filename: str | None = field(default=None)
88-
8987
dfn: ClassVar[Dfn]
88+
filename: str | None = field(default=None)
9089

9190
@property
9291
def path(self) -> Path:
@@ -180,19 +179,19 @@ def get_dfn(cls) -> Dfn:
180179
blocks=blocks,
181180
)
182181

183-
def _preio(self, format: str) -> None:
182+
def _preio(self, format: str = MF6) -> None:
184183
# prep for io operations
185184
if not self.filename:
186185
self.filename = self.default_filename()
187186

188-
def load(self, format: str) -> None:
187+
def load(self, format: str = MF6) -> None:
189188
"""Load the component and any children."""
190189
self._preio(format=format)
191190
self._load(format=format)
192191
for child in self.children.values(): # type: ignore
193192
child.load(format=format)
194193

195-
def write(self, format: str) -> None:
194+
def write(self, format: str = MF6) -> None:
196195
"""Write the component and any children."""
197196
self._preio(format=format)
198197
self._write(format=format)

flopy4/uio.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def register_writer(self, cls, format, function):
5757

5858
def load(self, cls, instance, *args, format=None, **kwargs):
5959
_load = self.get_loader(cls, format)
60-
_load(instance, *args, **kwargs)
60+
return _load(instance, *args, **kwargs)
6161

6262
def write(self, cls, instance, *args, format=None, **kwargs):
6363
_write = self.get_writer(cls, format)
@@ -71,14 +71,17 @@ def write(self, cls, instance, *args, format=None, **kwargs):
7171

7272

7373
class IO(property):
74-
"""Wrap a file IO descriptor as a property."""
74+
"""
75+
Custom property wrapper for IO operation descriptors.
76+
See the `astropy` source for more details/motivation.
77+
"""
7578

7679
def __get__(self, instance, owner_cls):
7780
return self.fget(instance, owner_cls)
7881

7982

8083
class IODescriptor:
81-
"""Base class for file IO operations, implemented as descriptors."""
84+
"""Base class for file IO operation descriptors."""
8285

8386
def __init__(self, instance, cls, op: Op, registry: Registry | None = None):
8487
self._registry = registry or DEFAULT_REGISTRY
@@ -107,7 +110,7 @@ class Loader(IODescriptor):
107110
def __init__(self, instance, cls):
108111
super().__init__(instance, cls, "load", registry=DEFAULT_REGISTRY)
109112

110-
def __call__(self, *args, **kwargs) -> None:
113+
def __call__(self, *args, **kwargs):
111114
return self.registry.load(self._cls, self._instance, *args, **kwargs)
112115

113116

@@ -118,4 +121,4 @@ def __init__(self, instance, cls):
118121
super().__init__(instance, cls, "write", registry=DEFAULT_REGISTRY)
119122

120123
def __call__(self, *args, **kwargs) -> None:
121-
return self.registry.write(self._cls, self._instance, *args, **kwargs)
124+
self.registry.write(self._cls, self._instance, *args, **kwargs)

0 commit comments

Comments
 (0)