Open dibellaa opened 3 weeks ago
Surest workaround is to exclude the said method in autodoc_default_options
adding something like this in your conf.py
:
autodoc_default_options = {
'exclude-members': 'model_post_init'
}
The bug you report seems uncommon and particular to the extensions you're using:
extensions = [ 'sphinx.ext.napoleon', 'sphinxcontrib.autodoc_pydantic', 'sphinx.ext.intersphinx', 'myst_parser', ]
The likely culprit isn't Sphinx core but the autodoc_pydantic extension since they say on their main page:
Perfect, let’s go. But wait, sphinx’ autodoc does not integrate too well with pydantic models 😕.
I think you should report this on their repo before you report it here.
This bug is reminiscent of some dataclass bugs since that type also has a __post_init__()
. However since pydantic models aren't part of the standard library it's a safer bet to ask the extension authors to make a diagnoses.
Describe the bug
I have a project that uses Pydantic. I recently updated it to v2 and I still use sphinx==7.2.6. I noticed in the autogenerated source documentation, that models have the method model_post_init. This method is not override in my project and it comes directly from Pydantic BaseModel.
How to Reproduce
I cannot share source since it is covered by copyright.
Environment Information
Sphinx extensions
Additional context
No response