sphinx-doc / sphinx-doc/sphinx

Allow transitions in docstrings

Open
#7,813 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

extensions:autosummary type:enhancement
Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Is your feature request related to a problem? Please describe.
I am trying to use transitions (----) in the docstrings of my Python package members but Sphinx outputs an error message when I do that and the generated html does not contain a transition.

Here is a minimal example. The function below belongs to my_module.

def foobar():
    r"""Foo

    ----

    Bar
    """
    pass

This is my Sphinx's main index.rst file:

.. autosummary::
    :toctree: _api_members

    my_module.foobar

Trying to make the html will output the following message:

docstring of my_module.foobar:3: WARNING: Unexpected section title or transition.

And as can be seen below, the output does not contain the expected transition.

image

I believe the only changes I did to my default conf.py are:

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.autosummary',
]

autosummary_generate = True
autosummary_imported_members = True

Describe the solution you'd like
I would like to be able to use ---- in docstrings similarly to regular rst.

Describe alternatives you've considered
The only way I found to solve this is to use raw html to print a <hr>, but this is really inelegant solution that polutes the docstrings.

def foobar():
    r"""Foo

    .. raw:: html

        <hr>

    Bar
    """
    pass

Producing the expected output with the horizontal rule:

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal docstring example and the conf.py settings for autodoc and autosummary, then build the index.rst example to reproduce the warning. Trace the docstring rendering path and verify that the build no longer reports an unexpected transition and that the generated HTML contains the transition.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.