You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't get the automatic docstring detection from #6563 to work using the example code.
Just to make sure, I created a new virtual environment and installed only Pydantic, and still cannot get it to work. Even with the use_attribute_docstrings=True, it still won't use the attribute docstrings.
I feel like I'm probably doing something wrong, but I'm stumped.
Example Code
frompydanticimportBaseModel, ConfigDict, FieldclassModel(BaseModel):
model_config=ConfigDict(use_attribute_docstrings=True)
x: str""" Example of an attribute docstring """y: int=Field(description="Description in Field")
""" Description in Field overrides attribute docstring """print(Model.model_fields["x"].description)
# Noneprint(Model.model_fields["y"].description)
# 'Description in Field'
Are you running this in an interactive terminal? If so, this won't work as Pydantic needs to have access to the source code of the class, as stated in the docs.
I'm not able to reproduce this issue. Perhaps double check the version of pydantic that you're using?
frompydanticimportBaseModel, ConfigDict, FieldclassModel(BaseModel):
model_config=ConfigDict(use_attribute_docstrings=True)
x: str""" Example of an attribute docstring """y: int=Field(description="Description in Field")
""" Description in Field overrides attribute docstring """print(Model.model_fields["x"].description)
# Example of an attribute docstringprint(Model.model_fields["y"].description)
# 'Description in Field'
Initial Checks
Description
I can't get the automatic docstring detection from #6563 to work using the example code.
Just to make sure, I created a new virtual environment and installed only Pydantic, and still cannot get it to work. Even with the
use_attribute_docstrings=True
, it still won't use the attribute docstrings.I feel like I'm probably doing something wrong, but I'm stumped.
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: