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
autodoc_typehints="description" doesn't use __init__ type hints #8178
Comments
The bug reported in #7329 was that, when The fix that was applied makes it so that This means that I suggest instead changing
The fix for #7329 fixed one special case of |
Previously, `__init__` type hints were not used when documenting a class using `autodoc_typehints="description"`. This was done to prevent documentation for parameters from showing up twice, but that will no longer occur now that parameter and return types are only inserted if the parameter or return has a description. Closes sphinx-doc#8178
Previously, `__init__` type hints were not used when documenting a class using `autodoc_typehints="description"`. This was done to prevent documentation for parameters from showing up twice, but that will no longer occur now that parameter and return types are only inserted if the parameter or return has a description. Closes sphinx-doc#8178
Previously, `__init__` type hints were not used when documenting a class using `autodoc_typehints="description"`. This was done to prevent documentation for parameters from showing up twice, both for the class and the `__init__` special method. As the new ``autodoc_typehint_undoc`` option provides a better way to prevent this bad behavior by placing the user in control of where the type hints are added, it is now safe to add type hints for documented `__init__` parameters. Closes sphinx-doc#8178
Previously, `__init__` type hints were not used when documenting a class using `autodoc_typehints="description"`. This was done to prevent documentation for parameters from showing up twice, both for the class and the `__init__` special method. As the new ``autodoc_typehint_undoc`` option provides a better way to prevent this bad behavior by placing the user in control of where the type hints are added, it is now safe to add type hints for documented `__init__` parameters. Closes sphinx-doc#8178
Previously, `__init__` type hints were not used when documenting a class using `autodoc_typehints="description"`. This was done to prevent documentation for parameters from showing up twice, both for the class and the `__init__` special method. As the new ``autodoc_typehint_undoc`` option provides a better way to prevent this bad behavior by placing the user in control of where the type hints are added, it is now safe to add type hints for documented `__init__` parameters. Closes sphinx-doc#8178
Previously, `__init__` type hints were not used when documenting a class using `autodoc_typehints="description"`. This was done to prevent documentation for parameters from showing up twice, both for the class and the `__init__` special method. As the new ``autodoc_typehint_undoc`` option provides a better way to prevent this bad behavior by placing the user in control of where the type hints are added, it is now safe to add type hints for documented `__init__` parameters. Closes sphinx-doc#8178
Addressed by #8539, which will ship as part of 4.0 |
Describe the bug
Type hints attached to the
__init__
method are not used whenautodoc_typehints="description"
, but are used whenautodoc_typehints="signature"
.To Reproduce
Create
module.py
with these contents:Create
index.rst
with these contents:Generate documentation into an
html
directory:python3.8 -msphinx -aE -C -D 'extensions=sphinx.ext.autodoc,sphinx.ext.napoleon' -D autodoc_typehints=description . html
Expected behavior
The
name
parameter of thePerson
constructor should have a(str)
type annotation, like thesalutation
parameter ofgreet
does. Whenautodoc_typehints="signature"
, the signature does include the: str
type annotation. Adding-D autoclass_content=both
causes the type hint to be used, but:autoclass_content="class"
like it is ifautodoc_typehints="signature"
, andautoclass_content=both
causes aReturn type: None
annotation to be added, which is not helpful for a constructor and which doesn't match the behavior ofautodoc_typehints="signature"
(there's no-> None
in that case).Environment info
Additional context
This appears to be intentional behavior as it was the fix for #7329, but I believe it is incorrect because it is inconsistent with how signature type hints are handled.
The text was updated successfully, but these errors were encountered: