sphinx-doc / sphinx-doc/sphinx

autodoc_preserve_defaults=True does not work with slices in default argument

Open
#9,704 0 comments 2 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

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.