If you stringify or write to disk the model with add_comments=True (or with "fields-only") and fields have multi-line comments (with config use_attribute_docstrings=True) or multi-line field descriptions (description="My cool string.\nWith a newline") the output yaml will be malfomed.
from typing import Annotated
from pydantic import BaseModel, Field
class MyModel(BaseModel):
"""My custom model.""" # This will become the header!
c: Annotated[float, Field(description="See three?\nPO")] = 3 # description will become a comment
will produce
# My custom model.
c: 3.14 # See three?
PO
Likewise something like
c: float = 3
"""
Comment line one
Comment line two
"""
with attribute docstrings will have the same issue, where Comment line two will be on a newline, and not commented out.
It would appear multi-line model comments work fine.
Version used: 1.6.0
If you stringify or write to disk the model with
add_comments=True(or with"fields-only") and fields have multi-line comments (with configuse_attribute_docstrings=True) or multi-line field descriptions (description="My cool string.\nWith a newline") the output yaml will be malfomed.will produce
Likewise something like
with attribute docstrings will have the same issue, where
Comment line twowill be on a newline, and not commented out.It would appear multi-line model comments work fine.
Version used: 1.6.0