Open dannbuckley opened 2 months ago
@dannbuckley
Thanks for this. Agreed that the mapping between the MF6 input spec and the Python/FloPy equivalent is not always clear. Your timing is excellent, we have just begun to think on this for the next major version.
Embedding Python type annotations in the DFN would be one approach, but I think we want to avoid coupling MF6 or any other program's input specification to Python. It's not MF6's concern how flopy represents input parameters, nor is it flopy's concern how MF6 does so — notwithstanding the fact that users must currently concern themselves with such, since flopy reproduces a lot of MF6 implementation details. But IMO we want to get away from that.
We could aim instead for a pythonic specification with a sound type-theoretic basis, which is translated under the hood into a form suitable for MF6 or whatever program FloPy is driving. I think there are a few parts to this, which could form the foundation of a generic plugin framework anyone could implement to bind flopy to a model code:
List[Period]
where Period
is either an alias for tuple[float, int, float]
or an explicit record classThis would also allow consistent APIs for MF6 and older MODFLOW programs, which is a major friction point as it stands.
@wpbonelli
I'll throw a couple of other options out here too. The dataclasses
module was added to the standard library in 3.7. I think it was meant as a replacement for named tuples, but is still somewhat limited. There's also attrs
, which I think has better support for inheritance/subclassing.
@dannbuckley we are working on an attrs
-based prototype right this moment, in fact!
do you mind editing the issue title? maybe "type hints for input specifications" or something reflecting the more general utility of typing annotations
@dannbuckley I had an initial look at how we might generate named tuples alongside the components they appear in and substitute them into docstrings and typehints, I think your suggestion to add type hints is achievable in the near term (pre v4). More to come soon
Is your feature request related to a problem? Please describe. The documentation for the "type recarray" entries in the dfn specifications is sometimes hard to understand. These parameters might be a little easier to understand if there were type annotations in the
__init__
definitions. This is sort of already done in the package docstring, but the docstring is written in MODFLOW descriptive types.Describe the solution you'd like Add an
annotation
line to the dfn specification to store Python type information, and modify the createpackages.py utility to add Python type annotations to the package__init__
definition.Example dfn change (sim-tdis.dfn):
Example
__init__
change after updating packages: (mftdis.py):Additional context Some examples: