Skip to content
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] Retrieve type of attributes from type hints when using google-style #8285

Closed
QuentinSoubeyran opened this issue Oct 4, 2020 · 0 comments
Labels
extensions:napoleon type:enhancement enhance or introduce a new feature
Milestone

Comments

@QuentinSoubeyran
Copy link
Contributor

Following google style guide for classes, I added an Attributes: section my classes docstring. As I have PEP 526 annotations (because I use attrs), I did not add types in the docstring., as per the style guide.

When generating the documentation with .. automodule:: from autodoc, with napoleon, the attributes are not typed. I tried using the :undoc-members: flag of automodule, but this resulted in duplicated attributes: one with the explanation, the other with the type-hint.

While it is possible to not use type hints with attrs and replace attr.s(auto_attribs=True) by attr.ib(), this is not an option for e.g. dataclasses. I also tried napoleon_use_ivar=True, which silenced sphinx's warnings but still resulted in two definition of the attribute in the documentation.

It would be nice if napoleon (or autodoc) extracted the type hint of the class, or merged the attributes when using :undoc-members:. That would avoid duplicated types definitions in either the code or the doc. Currently, either the code has an annotation and a type in the docstring, or the generated documentation has two entry for each attribute.

This might be related to #7582 and #4074 .

Additional info

@QuentinSoubeyran QuentinSoubeyran added the type:enhancement enhance or introduce a new feature label Oct 4, 2020
@tk0miya tk0miya added this to the 3.4.0 milestone Nov 17, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extensions:napoleon type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

2 participants