scanpydoc.elegant_typehints#
Format typehints elegantly and and fix automatically created links.
The Sphinx extension sphinx_autodoc_typehints adds type annotations to functions.
This extension modifies the created type annotations in four ways:
- It formats the annotations more simply and in line with e.g. - numpy.
- It defines a configuration value - qualname_overridesfor- conf.pythat overrides automatically created links. It is used like this:- qualname_overrides = { "pandas.core.frame.DataFrame": "pandas.DataFrame", # fix qualname "numpy.int64": ("py:data", "numpy.int64"), # fix role ..., } - The defaults include - anndata.AnnData,- pandas.DataFrame,- scipy.sparse.spmatrixand other classes in- scipy.sparse.- It is necessary since - __qualname__does not necessarily match the documented location of the function/class.- Once either sphinx issue 4826 or sphinx-autodoc-typehints issue 38 are fixed, this part of the functionality will no longer be necessary. 
- The config value - annotate_defaults(default:- True) controls if rST code like- (default: `42`)is added after the type. It sets sphinx-autodoc-typehints’s option- typehints_defaultsto- 'braces'
- Type annotations for - tuplereturn types are added:- def x() -> Tuple[int, float]: """ Returns: a: An integer b: A floating point number """ - will render as: