-
Notifications
You must be signed in to change notification settings - Fork 224
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
TYP: Add type hints and improve docstrings of load_tile_map function #3087
Conversation
Returns | ||
------- | ||
raster : xarray.DataArray | ||
raster | ||
Georeferenced 3-D data array of RGB values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now there are two sections, Return type
and Returns
, and the returned object is written in italic instead of bold style. I personally prefer the current documentation version, as I think the returned object and its data type should be stated together (analogous to the parameters).
current docs | updated docs |
---|---|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check if sphinx-autodoc-typehint provides an option to control the behavior. https://github.com/tox-dev/sphinx-autodoc-typehints#options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think sphinx-autodoc-typehint provides such an option, so there is little we can do unless we decide not to add type hints for the return values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a napoleon_use_rtype = True
option that was tried in #937. Does it work here, or is that what sphinx-autodoc-typehint is using?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try napoleon_preprocess_types = True
as suggested at sphinx-doc/sphinx#9394?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
napoleon_preprocess_types
True to convert the type definitions in the docstrings as references. Defaults to False.
When setting napoleon_preprocess_types = True
, raster
is parsed as type definitions, so it's rendered the same way as the return type DataArray
. Strictly speaking, it's still incorrect.
Actually, the name of the returned value should not appear in the NumPy-style docstrings (see https://www.sphinx-doc.org/en/master/usage/extensions/example_numpy.html#example-numpy). I.e., we should change
Returns
-------
raster
Georeferenced 3-D data array of RGB values.
to
Returns
-------
Georeferenced 3-D data array of RGB values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the name of the returned value should not appear in the NumPy-style docstrings (see https://www.sphinx-doc.org/en/master/usage/extensions/example_numpy.html#example-numpy). I.e., we should change
It looks like they are using something like
Returns
-------
xr.DataArray
Georeferenced 3-D data array of RGB values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That version doesn't have type hints for the return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Yvonne Fröhlich <[email protected]>
I'm merging this PR. The style issue of the function return value/type should be addressed separately (if there is a good solution). |
Preview: https://pygmt-dev--3087.org.readthedocs.build/en/3087/api/generated/pygmt.datasets.load_tile_map.html#pygmt.datasets.load_tile_map