Skip to content

autodoc_preserve_defaults doesn't work on class methods #10421

@Yoshanuikabundi

Description

@Yoshanuikabundi

Describe the bug

Default values for class methods are rendered as their __repr__, even with autodoc_preserve_defaults = True in conf.py.

How to Reproduce

Extract the attached example and run make html. Note that the default value for the argument of the regular and static methods render correctly as SOME_DEFAULT, but the default value for the class method renders as its repr.

classmethod_defaults_mre.zip

Expected behavior

All three methods' argument's default values should render as SOME_DEFAULT

Your project

https://github.com/sphinx-doc/sphinx/files/8620112/classmethod_defaults_mre.zip

Screenshots

Screenshot of the rendered attached example demonstrating incorrect rendering:

Screenshot of the rendered attached example demonstrating incorrect rendering

OS

Arch Linux

Python version

3.10.0

Sphinx version

Tested on 4.5 and current 5.x branch (commit 335bf51)

Sphinx extensions

sphinx.ext.autodoc

Extra tools

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions