Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodoc doesn't honor autodoc_typehints = 'description' for dataclasses #10235

Open
Cilyan opened this issue Mar 4, 2022 · 3 comments
Open

Comments

@Cilyan
Copy link

Cilyan commented Mar 4, 2022

Describe the bug

When documentation for a class decorated with the @dataclass decorator is generated by autodoc, the typehints are written to the class constructor signature, even if autodoc_typehints is set to 'description'.

This does not apply to other classes, even classes that derive from dataclasses, but are not dataclasses themselves.

It seems that the bug only appears if the class has no docstring (TBC).

How to Reproduce

$ git clone https://github.com/Cilyan/sphinx-dataclass-issue
$ cd sphinx-dataclass-issue
$ poetry install
$ cd docs
$ make html
$ # open _build/html/index and see class signatures

Expected behavior

Class signature should not include typehint even for dataclasses, when autodoc_typehints is set to 'description'.

Your project

https://github.com/Cilyan/sphinx-dataclass-issue

Screenshots

First class is dataclass, second class is not a dataclass.

image

OS

Linux 5.16.11-arch1-1 #1 SMP PREEMPT Thu, 24 Feb 2022 02:18:20 +0000 x86_64 GNU/Linux

Python version

3.10.2

Sphinx version

4.4.0

Sphinx extensions

sphinx.ext.autodoc

Extra tools

No response

Additional context

No response

@tk0miya
Copy link
Member

tk0miya commented Mar 6, 2022

This trouble comes from the conflict between autodoc_docstring_signature and autodoc_typehints. autodoc_docstring_signature can forcedly override signature via docstring. It ignores the process of the autodoc_typehints. It would be better to resolve this conflict.

@tk0miya tk0miya added this to the 5.0.0 milestone Mar 6, 2022
@tk0miya
Copy link
Member

tk0miya commented Mar 6, 2022

As a workaround, you can avoid this problem via 1) setting a docstring to your dataclass, or 2) disable autodoc_docstring_signature feature.

@Cilyan
Copy link
Author

Cilyan commented Mar 7, 2022

Workaround 1 seem the best option in my case, as I need to overload several signatures throughout the code.

@tk0miya tk0miya modified the milestones: 5.0.0, 5.x Apr 2, 2022
@AA-Turner AA-Turner modified the milestones: 5.x, 6.x Oct 4, 2022
@AA-Turner AA-Turner modified the milestones: 6.x, 7.x Apr 29, 2023
@AA-Turner AA-Turner modified the milestones: 7.x, 8.x Jul 20, 2024
@AA-Turner AA-Turner modified the milestones: 8.x, some future version Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants