Do you have to type out numpy.ndarray in full for a type hint in a Google-style docstring, or can you just type np.ndarray?

I’ve been reading through this guide to writing Google-style and Numpy-style docstrings with type hints for numpy ndarrays. In the Numpy-style docstring example, type hints are abbreviated as "np.ndarray". However, in the corresponding Google-style example, the type is written as "numpy.ndarray".

Is it possible to use "np.ndarray" as a type in a Google-style docstring, or must one write out "numpy.ndarray" in full?

I haven’t been able to find any other examples of numpy types being used in a Google-style docstring, but I did see one where "pandas.dataframe" was written out in full.

If it’s possible to use both, which is the correct one according to the Google-style guidelines?

I’m using the napoleon extension in sphinx for generating autodocs.

Also, I’m not sure if using I’m "type hints" in the correct context above. Is the type specification in a python docstring called a "type hint", or is that only the name used for the actual type hints in the python language itself?

Source: Python Questions

LEAVE A COMMENT