-
Notifications
You must be signed in to change notification settings - Fork 3
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
Support PEP 484 type hinting to populate docstrings #25
Comments
Hi @jonathansick, has there been any update on this issue? I would like to use type annotations in my DAX API code. |
I haven't done the work yet on the documentation production side, but there's nothing stopping you from using type annotations in DAX code. |
I had a chance to test
Since both sphinx-autodoc-typehints and numpydoc both manipulate docstrings, it's possible that the return type issue could be resolved with more sophisticated post-processing of the docstring. The following are screenshots of the output for different types of APIs with different versions of the build chain. I looked at numpydoc with sphinx-autodoc-typehints, as well as using Napoleon with sphinx-autodoc-typehints. Numpydoc and Napoleon present parameter slightly differently (definition list versus list). There's no clear advantage to using Napoleon from what I can see here. Typed functionnumpydoc with sphinx-autodoc-typehints. Notice how the return type is on a separate line from the return description. numpydoc without sphinx-autodoc-typehints. napoleon with sphinx-autodoc-typehints. Data classnumpydoc with sphinx-autodoc-typehints. napoleon with sphinx-autodoc-typehints. Function without type annotationsnumpydoc with sphinx-autodoc-typehints. numpydoc without sphinx-autodoc-typehints. napoleon with sphinx-autodoc-typehints napoleon without sphinx-autodoc-typehints |
There are two Sphinx extensions that support PEP 484 type hints for functions parameters:
Although I won't confirm it as the optimal choice, https://github.com/agronholm/sphinx-autodoc-typehints seems to be a more active project.
Based on my reading, it seems that these projects are already compatible with tools that parse docstrings. The key is to add the
sphinx_autodoc_typehints
extension afterautodoc
, but before a parser like numpydoc or Napoleon.I haven't yet confirmed that
numpydoc
works, though it should given that Napoleon does work.The text was updated successfully, but these errors were encountered: