OSGeo / grass

GRASS GIS - free and open-source geospatial processing engine
https://grass.osgeo.org
Other
854 stars 311 forks source link

temporal: Add precise typing overloads to dataset_factory #4600

Closed echoix closed 1 month ago

echoix commented 1 month ago

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.