Support type annotations (PEP 484)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 355
- Forks
- 181
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 3
Description
With support for Python 2.7 being dropped in a number of projects, some might consider using type annotations from PEP 484.
In particular, see discussions in https://github.com/numpy/numpy-stubs, https://github.com/pandas-dev/pandas/issues/14468 https://github.com/scipy/scipy/issues/9038 https://github.com/scikit-learn/scikit-learn/issues/11170
A recurrent issue when using type annotations is that one has then to keep consistency between types in the docstring and type annotations which is extra work and can be tedious.
It would be great if numpydoc could take the type information from annotations. For instance,
def func(x):
"""Some function
Parameters
----------
x : int
Description of parameter `x`.
"""
could optionally be written as,
def func(x: int):
"""Some function
Parameters
----------
x
Description of parameter `x`.
"""
and generate the same HTML.
To keep backward compatibility this mechanism could be enabled with an optional config flag, and only be used if the type is not provided in the docstring.
For docstring formatting without numpydoc this functionality is implemented in sphinx-autodoc-typehints (that also works with sphinx.napoleon). So maybe integration with that extension could be a possibility.
This would also have the added benefit that type annotations, unlike docstrings types, can be programmatically checked for consistency (e.g. with mypy)..
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PEP 484 examples and the existing numpydoc and sphinx-autodoc-typehints behavior described in the issue. Define how an optional configuration flag should use annotations only when a docstring type is absent, while preserving existing HTML output and avoiding conflicting type information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100