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

[autodoc] Allow :annotation: to be used in docstring #8022

Closed
Jackenmen opened this issue Jul 31, 2020 · 6 comments
Closed

[autodoc] Allow :annotation: to be used in docstring #8022

Jackenmen opened this issue Jul 31, 2020 · 6 comments
Labels
extensions:autodoc type:enhancement enhance or introduce a new feature
Milestone

Comments

@Jackenmen
Copy link

Is your feature request related to a problem? Please describe.
Currently if I want to add an attribute (or module constant) and document it with-in a code (let's assume autoclass/automodule is in usage), I can't stop Sphinx from showing the value of it in that same docstring. Instead, I have to manually do this in automodule directive:

 .. automodule:: module_name
     :members:
+    :exclude-members: CONSTANT_NAME
+
+    .. autodata:: CONSTANT_NAME
+        :annotation:

Describe the solution you'd like
I would want to be able to just add :annotation: directly in the docstring.

Describe alternatives you've considered
Other than naming this role differently in docstring, I don't think there's anything else to do if I want to control this from docstring.

Additional context
N/A

@Jackenmen Jackenmen added the type:enhancement enhance or introduce a new feature label Jul 31, 2020
@tk0miya tk0miya added this to the 3.3.0 milestone Aug 1, 2020
@tk0miya
Copy link
Member

tk0miya commented Aug 1, 2020

+1: Reasonable. Please let me know your opinion before implementation. Is there any reason to control :annotation: individually? Could you accept an option to suppress them all on the document instead of this?

@Jackenmen
Copy link
Author

Is there any reason to control :annotation: individually?

I think that individual control might not be as needed in class, but I think that it does make sense to be able to control individual appearance of constants in module. I admit that I don't use auto attribute that often, but from my point of view, the most common use case is to just not show the value of the constant for some specific constant while keeping it for the rest. But if someone uses :annotation: to actually make it show different value, then this is even more important since setting same :annotation: some_value for whole document wouldn't make much sense.

IMO controlling individual :annotation: from docstring would be the must for this, and controls for class-wide and module-wide (maybe document-wide too, I don't know) are just things that could be "good to have" rather than really necessary.

@tk0miya
Copy link
Member

tk0miya commented Aug 1, 2020

Ah, sorry. I'd like to ask your opinion about adding a new configuration like autodoc_suppress_values_for_attributes = True instead of :annotation: option support in docstring. I suspect it controls all of attributes in the Sphinx project. I'm a bit hesitating to add a new metadata to docstring yet. So it might be better to add a new configuration if it satisfies your case.

@Jackenmen
Copy link
Author

Oh, I actually thought that such option already exists, but since it would not be useful for me, I didn't check for that in Sphinx's docs.
So yeah, such option wouldn't really be useful for me, as I usually want to show the values of variables/attributes and only sometimes (rather rarely) don't want to show it. I would even say that it's rare enough that I can just do what is shown in the example above, but I like keeping all of this to attribute's docstring rather than changing it in rst file (same as I can for example do with :meta private: since Sphinx 3.0).
IMO a good example of this are enums:

class PermState(enum.Enum):
    NONE = enum.auto()
    """No special privilege level."""
    MOD = enum.auto()
    """User has the mod role."""
    ADMIN = enum.auto()
    """User has the admin role."""
    GUILD_OWNER = enum.auto()
    """User is the guild owner."""
    APP_OWNER = enum.auto()
    """User is an app owner."""


class ConfigCategory(enum.Enum):
    """Represents config category."""

    #: Global category.
    GLOBAL = "GLOBAL"
    #: Guild category.
    GUILD = "GUILD"
    #: Channel category.
    CHANNEL = "TEXTCHANNEL"
    #: Role category.
    ROLE = "ROLE"
    #: User category.
    USER = "USER"
    #: Member category.
    MEMBER = "MEMBER"

While the value of PermState is unimportant (which is why enum.auto() is used), the value of ConfigCategory does have a meaning and showing it in documentation can make sense.

I'm a bit hesitating to add a new metadata to docstring yet. So it might be better to add a new configuration if it satisfies your case.

So in short, it does not satisfy my case, but this is not a critical feature but rather an enhancement, so if you think this shouldn't be added to Sphinx yet, I'll accept that and just keep using the current solution for this with the hope that maybe some day it can be replaced with something that better suits my needs :)

@tk0miya
Copy link
Member

tk0miya commented Aug 2, 2020

Thank you for comment. And I agree with your example PermState. I'll consider what we should do again. Please wait a moment.

@dfremont
Copy link
Contributor

dfremont commented Sep 5, 2020

I'd also find this useful: I have some large modules which are auto-documented (using autodoc + napoleon) but have a few attributes whose values are rendered as very long strings. If I were writing my own autodata directives I could use :annotation: to specify an abbreviated form of the value, but I'd much rather have everything automatically generated from the docstrings.

@tk0miya tk0miya modified the milestones: 3.3.0, 3.4.0 Oct 27, 2020
@tk0miya tk0miya modified the milestones: 3.4.0, 3.5.0 Dec 20, 2020
tk0miya added a commit that referenced this issue Dec 28, 2020
Close #8022: autodoc: Allow to hide the value of the variables via metadata
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extensions:autodoc type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

3 participants