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: more custom docstring section styles #8573

Closed
SolidifiedRay opened this issue Dec 21, 2020 · 3 comments
Closed

Napoleon: more custom docstring section styles #8573

SolidifiedRay opened this issue Dec 21, 2020 · 3 comments
Labels
extensions:napoleon type:enhancement enhance or introduce a new feature

Comments

@SolidifiedRay
Copy link
Contributor

SolidifiedRay commented Dec 21, 2020

Although the napoleon_custom_sections option help renders custom docstring section, the style is inconsistent with the rest of the doc.

For example, I have a custom docstring section Side Effect. I would like it to be displayed as returns or parameters docstring section. However, napoleon_custom_sections option rendesr Side Effect in a different style shown in the following picture.

微信截图_20201221155650

It will be really helpful if we can customize the custom sections a bit more. The following setting has a similar effect, but it renders the Parameters name instead of the custom name.

napoleon_use_param = False
napoleon_custom_sections = [('Custom name', 'Parameters')]

I would like to do something like the following so that my Custom section has the same style as the Parameter section, and it still keeps my custom name:


napoleon_custom_sections = [("Side Effects", "display_like_parameters"), ...]

or

napoleon_custom_sections = [("Side Effects", "Parameters") ]
napoleon_custom_section_rename = False # True is default for backwards compatibility.

The following link includes more details about the solutions:
Format custom "Side Effects" docstring section in-toto/in-toto#401

Others people have expressed a similar desire (see sphinx-contrib/napoleon#2)

If you are interested, I would like to provide a PR for this. Thanks!

@SolidifiedRay SolidifiedRay added the type:enhancement enhance or introduce a new feature label Dec 21, 2020
@tshead
Copy link

tshead commented Dec 22, 2020

Boy, I could really use this right away. If it were up to me:

  • napoleon_custom_sections would be called napoleon_custom_aliases, and only accept a list of (new alias, existing section) tuples.
  • A hypothetical new napoleon_custom_sections would only accept a list of (new section, existing section) or (new section, callback function) tuples, and the output would always use new section as the title, in either case.

That would be a backwards-incompatible change, but you could argue that the current behavior isn’t actually documented in the Sphinx docs, and thus is fair game.

Cheers,
Tim

@tk0miya
Copy link
Member

tk0miya commented Dec 24, 2020

I also don't know napoleon module has such option. It was added at #4387. It has not been documented, but it was introduced in CHANGES. So I consider it's a secret feature. So -1 for incompatible change.

But I'm interested in the enhancement itself. Could you submit a PR please? I'll take a look.

@SolidifiedRay SolidifiedRay changed the title Napoleon: configure custom docstring section style Napoleon: more custom docstring section styles Jan 5, 2021
SolidifiedRay added a commit to SolidifiedRay/sphinx that referenced this issue Jan 5, 2021
SolidifiedRay added a commit to SolidifiedRay/sphinx that referenced this issue Jan 5, 2021
SolidifiedRay added a commit to SolidifiedRay/sphinx that referenced this issue Jan 5, 2021
SolidifiedRay added a commit to SolidifiedRay/sphinx that referenced this issue Jan 5, 2021
@SolidifiedRay
Copy link
Contributor Author

Sorry for the late reply. I just submit a PR #8658. You might want to have a look when you find some times. @tk0miya
Thank you and happy new year!

SolidifiedRay added a commit to SolidifiedRay/sphinx that referenced this issue Jan 17, 2021
SolidifiedRay added a commit to SolidifiedRay/sphinx that referenced this issue Jan 18, 2021
tk0miya added a commit that referenced this issue Jan 19, 2021
Close #8573: napoleon: Add more custom section styles
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 15, 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

3 participants