-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[napoleon] Clarify whether there is actual support for type annotations #2738
Comments
Regarding PEP 484The Napoleon examples of functions with and without PEP 484 annotations:
So you can see there are some slight differences. Using PEP 484 annotations, the types will be rendered inline with the function declaration. I have a feeling this will become the de facto standard as more people become comfortable writing type annotations. |
Thanks so much for the detailed answer! It'd be great if some of this can make its way to… somewhere more visible. 😃 (Also it's interesting to know about the possibility of use without Sphinx). The one case you didn't cover regarding PEP 484 is the comment syntax for Python 2-compatible code, this example from the docs: def func(arg1, arg2):
# type: (int, str) -> bool
"""Summary line.
Extended description of function.
Args:
arg1: Description of arg1
arg2: Description of arg2
Returns:
Description of return value
"""
return True That's my current interest so that's why I wasn't seeing anything. I suppose it'd be a matter of Sphinx itself (or autodoc) having support for this form of type information so that Napoleon could use it too—I'm not sure if there is any support for this, I'll search around for info or related tickets. |
I'll add a line explaining that the Python 2-compatible annotations aren't supported. For some reason, I thought those worked :( |
@RobRuana Thanks for your explanation regarding output of docs with and without type annotations. I was wondering if there is a way to get the |
The above described functionality would be really great! |
Agreed. In particular the combination with |
For introspection purposes, function type annotations should be the preferred approach Agree with @ostrokach 's suggestion to note types in the parameter definitions. This presents the relevant information in a more contextually appropriate location - easier for readers to digest. It would further be good to have an option to remove the parameter types from the function signatures (in the documents). The typing information clutters the signatures, quickly becoming a readability issue for complex functions or parameters consisting of multiple or nested types. |
This extension is worth trying: It moves type hints from function signatures to the parameter description. I'm using it with |
I may be a victim of circumstances here, but I was left a bit confused.
sphinx.ext.napoleon
, there is no type information reflected in generated documentation if I use that style. I wasn't sure whether this just isn't actually supported, because the doc isn't really explicit about that, but I initially took it as implied.sphinx-contrib
first (which I rooted around to find on Bitbucket) and whether there might be newer features that I'm missing when using built-insphinx.ext.napoleon
. This may be true (?), but checking in the changelog I didn't see anything regarding type annotation support anyway.So, a couple of things I'm left feeling:
Maybe this exists somewhere but it wasn't along my circumstantial path above.
The text was updated successfully, but these errors were encountered: