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

Add model_config = ConfigDict(use_attribute_docstrings=True) when the command option --use-field-description is used #2049

Open
9ao9ai9ar opened this issue Jul 30, 2024 · 1 comment

Comments

@9ao9ai9ar
Copy link

The use_attribute_docstrings key is available in Pydantic v2.7+ that enables docstrings of attributes to be used for field descriptions. If the value is the default False, the examples in the linked documentation would print None. It'll be nice for the docstrings to still be accessible via Model.model_fields["x"].description, just like if it's defined using Field(description="Description in Field").

@menzenski
Copy link

Also interested in this. We use a workaround today to get this behavior, by defining a base class which sets use_attribute_docstrings:

# my_library/_base.py

from pydantic import BaseModel, ConfigDict

class MyBaseModel(BaseModel):
    model_config = ConfigDict(
        use_attribute_docstrings=True,
    )

Then we pass the option --base-class my_library._base.MyBaseModel to the datamodel-codegen command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants