Skip to content

Conversation

@avhz
Copy link

@avhz avhz commented Oct 31, 2025

This PR should add support for Pydantic computed_field descriptions.

This is in addition to the current support for Field descriptions, so it just allows for consistency when documenting Pydantic models.

See issue #854

Let me know your thoughts !

Thanks again for the useful project :)

pdoc/doc.py Outdated
elif _doc := _pydantic.get_computed_field_docstring(
cast(type, self.obj),
name,
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep pydantic compexity out of pdoc.doc as much as possible. Can we please integrate this into get_field_docstring so that pdoc.doc remains pretty much unchanged? Computed fields are also still fields, so this is fine. :) Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, I've moved it into get_field_docstring

Copy link
Member

@mhils mhils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks great except for the CI failures.

@avhz
Copy link
Author

avhz commented Oct 31, 2025

Should be all good now.

There is a known issue with mypy when using the computed_field + property idiom.

See here: https://docs.pydantic.dev/2.0/usage/computed_fields/

@avhz
Copy link
Author

avhz commented Nov 1, 2025

Just added a brief note in the docs regarding this addition :)

Copy link
Member

@mhils mhils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Can you please add a CHANGELOG entry? Otherwise LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants