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

Getting duplicate object definitions for class attributes when having both docstring and type hints. #12483

Closed
ahan2911 opened this issue Jun 27, 2024 · 2 comments
Labels

Comments

@ahan2911
Copy link

Describe the bug

When using both sphinx_autodoc and sphinx_autodoc_typehints extensions. And in class having attribute definition in docstring as well as type hint for the same. Then getting duplicate object definitions.
Is there any way to prefer docstring over type hint for definition of object. I want both extensions to be enabled.

How to Reproduce


conf.py

Configuration file for the Sphinx documentation builder.

For the full list of built-in configuration values, see the documentation:

https://www.sphinx-doc.org/en/master/usage/configuration.html

-- Project information -----------------------------------------------------

https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'General Project'

-- General configuration ---------------------------------------------------

https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.napoleon',
'sphinx_autodoc_typehints',
'sphinx.ext.autodoc',
'sphinx.ext.duration',
'sphinx.ext.viewcode'
]

templates_path = ['_templates']
exclude_patterns = []

-- Options for HTML output -------------------------------------------------

https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'

html_static_path = ['_static']


index.rst

Welcome to General Project's documentation!

.. automodule:: role
:members:
:undoc-members:
:show-inheritance:

Indices and tables

  • :ref:genindex
  • :ref:modindex
  • :ref:search

role.py

"""Module for Role schemas"""
from pydantic import BaseModel, ConfigDict

class Role(BaseModel):
"""
Pydantic model for Role schema.

Attributes:
    Id (int): Primary key for the role.
    GroupId (str): Group Id of the role.
    RoleName (str): Name of the role.
"""
model_config = ConfigDict(from_attributes=True)
Id: int
GroupId: str
RoleName: str

Environment Information

Platform:              win32; (Windows-10-10.0.22621-SP0)
Python version:        3.11.9 (tags/v3.11.9:de54cf5, Apr  2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)])
Python implementation: CPython
Sphinx version:        7.3.7
Docutils version:      0.20.1
Jinja2 version:        3.1.4
Pygments version:      2.18.0

Sphinx extensions

No response

Additional context

No response

@electric-coder
Copy link

electric-coder commented Jun 27, 2024

Can you please edit the post to fix the source fences?

using both sphinx_autodoc and sphinx_autodoc_typehints extensions

Since this is an issue specific to the sphinx_autodoc_typehints extension I think you should ask at their repository. This is bound to be a common usage question so also consider searching the Sphinx tag at Stack Overflow. Please see the Get Help because this issue tracker is mostly for bugs and feature requests, not for usage questions.

@jayaddison
Copy link
Contributor

This seems potentially similar to an issue already reported in sphinx-autodoc-typehints at tox-dev/sphinx-autodoc-typehints#419 - please feel free to correct me if I'm mistaken.

@jayaddison jayaddison closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants