temporal: Add precise typing overloads to dataset_factory #4600
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.
This PR adds precise typing overloads to grass.temporal.factory's dataset_factory function. This enables type checkers like mypy or Pyright for example to understand the returned class from the string passed as the type argument. Combined with returning directly the dataset, this function is almost completely typed.
For example, in grass.temporal.univar_statistics, the IDE can show what overload dataset_factory is using, and the type of
sp
can be inferred toSpaceTimeVectorDataset
Also, it improves the sphinx generated docs. Our current sphinx build process can understand and use the typing information, plus show the overloads too, linking to classes in our docs when appropriate. Below are before/after screenshots. Note that with trial-and-error, the non-overloaded (implementation) function signature isn't shown anymore, that's why a more generic signature was used
Before:
After:
In a previous iteration, I tried using a python typing stub file, a .pyi file, but even though the IDE experience was the same, since it wasn't installed like other python files, the sphinx doc generation didn't show the improvements like on the screenshots. I didn't try editing the makefiles to be able to copy pyi files too in the install location to see if it would have the same effect.