-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(codegen/docs): add type hints #2317
Draft
wpbonelli
wants to merge
46
commits into
modflowpy:develop
Choose a base branch
from
wpbonelli:2298
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 tasks
wpbonelli
added a commit
to MODFLOW-USGS/modflow6
that referenced
this pull request
Oct 8, 2024
Add 'in_record true' to several record fields in utl-ts.dfn and utl-tas.dfn. Motivated by modflowpy/flopy#2317. FloPy can infer this, evidently, but a less clever (and ideally much simpler) implementation may require them explicitly. IMO it makes sense to do this anyway for consistency's sake, at least while the DFN specification is flat and record membership cannot be inferred directly from the spec's structure. This is not necessarily comprehensive, further work may reveal the same (or similar) updates are needed elsewhere.
wpbonelli
changed the title
refactor(codegen/docs): jinja templates, type hints
refactor(codegen/docs): add type hints
Nov 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sketching #2298, and possibly moving the templating in
flopy/mf6/utils/createpackages.py
to JinjaAiming to minimally/faithfully reproduce component source files, adding type hints in
__init__
and the docstrings.Type mapping
Not sure the mapping is right, but so far
Array variables
I think while variables can be specified as
NDArray
with a type parameter, method/function implementations are lenient andNDArray
can be switched toArrayLike
for type hinting. Conversely we might be able to usendarray[Shape, T]
whereShape = Tuple[str, ...]
in a specification to defer shape checking until dimensions can be looked up from other parameters — this possible because numpy leaves the shape parameter wide open (it need not be a tuple of int)Tagged records in keystrings
For records whose last item repeats, I considered doing:
Tuple[Any, ...]
Tuple[Union[Literal, T], ...]
Tuple[Literal, Tuple[T, ...]]
Ended up going with the latter.
Checking correctness
The correctness of this could be checked with tests or maybe mypy? Not sure about checking completeness — i.e. do the type hints truly cover all accepted types. For instance I think single-value records can be provided directly, without a wrapping tuple.
Todo
NDArray
asArrayLike
Motivation
This is a first step toward refactoring
mfstructure.py
and determining what is really necessary to represent an input data model. In the meantime this grows the codebase instead of shrinking it, but I am thinking of it a bit like scaffolding before renovation. Some complexity in the implementation is ascribable to the current framework and could simplify eventually.