Skip to content

feature: handle descriptions formatted using dedent() #50

@analog-cbarber

Description

@analog-cbarber

Is your feature request related to a problem? Please describe.

We often use textwrap.dedent to format multiline descriptions in our pydantic models, e.g.:

class MyModel(BaseModel):
    something: int = Field(
        descripion = dedent(
            """
            Here is the description.
            """
        ),
    )

This allows us to have nicely formatted descriptions in our source but strip out the leading whitespace
from the multi-line string literal. This is a fairly common convention for pydantic models with complex
description fields.

However, it appears that griffe[-pydantic] does not handle this construct and as a result such fields
end up having no description shown in the generated docs.

Describe the solution you'd like

I would like griffe-pydantic to implicitly handle this and treat dedent() as a standard string literal transformation.

Describe alternatives you've considered

The only workaround I can think of currently is to duplicate the description in a doc-string. This appears
to work but has obvious issues with maintenance:

class MyModel(BaseModel):
    something: int = Field(
        descripion = dedent(
            """
            Here is the description.
            Second line.
            """
        ),
    )
    """
    Here is the description.
    Second line.
    """

Additional context

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions