sphinx-doc / sphinx-doc/sphinx
autodoc_preserve_defaults=True does not work with slices in default argument
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
When using the autodoc_preserve_defaults=True option, any slicing operator being present in the default arguments results in a warning
WARNING: Failed to parse a default argument value for <function func at 0x7f56f5fdc430>: Unable to parse Slice object
and a fully expanded default argument (as if autodoc_preserve_defaults was not set at all).
How to Reproduce
Dedicated minimum working example:
$ git clone https://github.com/dokempf/mwe_autodoc_preserve_defaults.git
$ cd mwe_autodoc_preserve_defaults
$ pip install -r requirements.txt
$ cd docs
$ make html
Expected behavior
Documentation should show the default argument including the slice operator.
Your project
https://adaptivefiltering.readthedocs.io/en/latest/#adaptivefiltering.DataSet.save_mesh
Screenshots
No response
OS
Linux
Python version
3.9.7
Sphinx version
4.2.0
Sphinx extensions
sphinx.ext.autodoc
Extra tools
No response
Additional context
No response
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 by running the linked minimum working example with pip install -r requirements.txt and make html, then inspect the sphinx.ext.autodoc handling involved in preserving default arguments. Done means the generated documentation retains slice expressions in defaults without emitting the reported warning.
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
- 35/100