Skip to content

Conversation

jinnovation
Copy link
Contributor

@jinnovation jinnovation commented May 1, 2025

Contributes to #793.

This PR implements quick-and-dirty support for Pydantic-style default values and field descriptions. In other words, the following two classes will render equivalently:

class Foo(pydantic.BaseModel):
    """Foo class documentation."""

    a: int = pydantic.Field(default=1, description="Docstring for a")

class Foo(pydantic.BaseModel):
    """Foo class documentation."""

    a: int = 1
    """Docstring for a"""

Open questions:

  • Should Pydantic support for pdoc be split out into a separate "plugin" package, e.g. pdoc-pydantic or pdoc[pydantic]?
  • Is this the best place for default-value-extraction logic for Pydantic classes to live?

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!

Should Pydantic support for pdoc be split out into a separate "plugin" package, e.g. pdoc-pydantic or pdoc[pydantic]?

Too much complexity for now. I think pydantic is popular enough to have support for it builtin for now.

Is this the best place for default-value-extraction logic for Pydantic classes to live?

Pragmatically yes. See my comments below on how we can keep things reasonably clean.

@jinnovation jinnovation marked this pull request as draft May 2, 2025 17:23
@jinnovation

This comment was marked as resolved.

@jinnovation
Copy link
Contributor Author

Two issues related to rendering Pydantic model docs that I propose treating as out-of-scope for this PR:

  • If user's BaseModel subclass does not have its own class-level docstring, we end up rendering the docs for BaseModel itself;
  • We render the docs for model_config, which is typically only useful to implementers of the class and not to users thereof, i.e. the expected audience for the generated docs
image

@jinnovation jinnovation marked this pull request as ready for review October 11, 2025 09:42
@jinnovation jinnovation requested a review from mhils October 11, 2025 19:36
@jinnovation jinnovation requested a review from mhils October 17, 2025 03:08
@jinnovation
Copy link
Contributor Author

@mhils: This is ready for your eyes again!

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, great progress! 😃

@jinnovation jinnovation requested a review from mhils October 19, 2025 21:32
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 for the fast revision!

@jinnovation jinnovation requested a review from mhils October 21, 2025 02:46
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