sphinx-doc / sphinx-doc/sphinx

autodoc doesn't correctly document properties if getters/setters have different function names

Open
#9,677 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

Methods with the @property decorator can have a different method name for the setter, like shown below:

    @property
    def username(self) -> str:
        """
        :getter: gets username

        :setter: sets username
        """
        return self._username

    @username.setter
    def set_username(self, val: str) -> None:
        self._username = val

They are the same property, and should be rendered as one like this:

image

But sphinx autodoc adds an extra property for the setter with the exact same docstring information when using autoclass:

image

How to Reproduce
$ git clone https://github.com/miaowware/callsignlookuptools.git
$ cd callsignlookuptools
$ pip install -r devrequirements.txt
$ cd docs
$ make html
$ # open _build/html/api.html and see the duplicate properties
Expected behavior

Only this property is shown in the docs:

image

Your project

https://github.com/miaowware/callsignlookuptools

OS

Void Linux

Python version

3.9.7

Sphinx version

4.0.3

Sphinx extensions

sphinx.ext.autodoc, sphinx_autodoc_typehints, sphinxcontrib.fulltoc, enum_tools.autoenum

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 by reproducing the duplicate-property output with the provided callsignlookuptools example: install devrequirements.txt, enter docs, and run make html. Investigate autodoc's handling of @property and differently named setter methods; done means autoclass renders the getter and setter as one property without duplicate documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.