sphinx-doc / sphinx-doc/sphinx

[FEATURE] "Bases: [...]" added by ClassDocumenter.add_directive_header must not be part of the directive header.

Open
#11,275 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When asked, the ClassDocumenter.add_directive_header adds a line Bases: [...] containing the parent classes. However, custom implementations are no longer allowed to put additional directive options since they will be considered part of the docstring and not part of the directive options block.

https://github.com/sphinx-doc/sphinx/blob/669bcc0a190ce9921451bad28431886fbaad170b/sphinx/ext/autodoc/__init__.py#L1656-L1696

Additionally, since ClassDocumenter.add_directive_header does something before calling super().add_directive_header(), then a custom implementation must either reimplement the whole method or make it so that

https://github.com/sphinx-doc/sphinx/blob/669bcc0a190ce9921451bad28431886fbaad170b/sphinx/ext/autodoc/__init__.py#L1675

fails and manually adds the bases at the very end. Both solutions are highly dependent on the implementation of ClassDocumenter.add_directive_header, but we should prevent this. I therefore suggest adding a separate hook in the ClassDocumenter that is entirely responsible for adding the "Bases: ..." after the directive header has been processed. For me, "Bases: [...]" must not be part of the directive header (at least, according to the docutils specifications).

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 in sphinx/ext/autodoc/init.py, especially ClassDocumenter.add_directive_header and the linked lines around 1656–1696. Trace how the directive header is assembled and how the Bases line is added; done means the Bases line is emitted after directive options are processed without requiring custom implementations to reimplement the method.

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.