Skip to content

Support pydantic.computed_field #854

@avhz

Description

@avhz

Problem Description

Currently pdoc generates docs from pydantic.Field descriptions, e.g.

class Foo(BaseModel):
    x: int = Field(1, description="Important number")

However, Pydantic also provides computed_field which is useful alongside functools.cached_property, such as:

class Foo(BaseModel):
    @computed_field(description="Important number that takes ages to calculate")
    @cached_property
    def x(self) -> int:
        return 1

Proposal

I propose pdoc supports computed_field descriptions, since these are treated as attributes rather than methods, and it would provide consistency when documenting both Fields and computed_fields.

Alternatives

The alternative is to just use the standard documentation method, i.e.

class Foo(BaseModel):
    @computed_field
    @cached_property
    def x(self) -> int:
        """Important number that takes ages to calculate"""
        return 1

Thanks for the great project !

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions