autodoc_pydantic
autodoc_pydantic copied to clipboard
`model_post_init` from `BaseModel` appears in the rendered documentation
See screenshot. This is not supposed to happen, right?
Here is an MWE.
The problem appears when I provide a custom __init__
for the model (like shown here).
class Test(BaseModel):
field: str = Field(description="My field")
_field: str = PrivateAttr()
def __init__(self, **data):
super().__init__(**data)
self._field = self.field
Workaround: Add a :exclude-members: model_post_init
directive.
You can also exclude everything on BaseModel with the :inherited-members: BaseModel
directive
@helgee Have you tried @j-carson solution and is it feasible for you?
@mansenfranzen I suggested that workaround since my last PR had been hanging out for so long without response.
Pydantic 2 has a documented naming convention that the items it adds via the BaseModel class will all start with "model_" -- it seems like the better long-term solution would be an autodoc pydantic option to bulk-drop these attributes rather than a hardcoded list in the autodocumenter's __init__
method since the exact list has changed over time.