sphinx-doc / sphinx-doc/sphinx
Allow transitions in docstrings
Nobody has claimed this yet.
- 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.

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:

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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