Skip to content
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

temporal: Add precise typing overloads to dataset_factory #4600

Merged
merged 7 commits into from
Oct 27, 2024

Conversation

echoix
Copy link
Member

@echoix echoix commented Oct 27, 2024

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 to SpaceTimeVectorDataset
image

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:
image
After:
image

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.

@github-actions github-actions bot added Python Related code is in Python libraries labels Oct 27, 2024
@echoix echoix enabled auto-merge (squash) October 27, 2024 12:20
@echoix echoix merged commit ffcb9e1 into OSGeo:main Oct 27, 2024
26 checks passed
@github-actions github-actions bot added this to the 8.5.0 milestone Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libraries Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants