Support default values specified in Pydantic Models
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 228
- PR merge metrics
- No merged PRs in 30d
Description
Problem Description
My codebase leverages Pydantic heavily. In particular, we use Pydantic Models heavily as a "superpowered" form of dataclasses. In particular, we use the Field() function heavily to validate, specify defaults, and otherwise impose restrictions on the values passed into a given field.
Unfortunately, for Pydantic Model fields, it seems that the default value -- whether specified in Field() or "normally" -- ends up not rendering properly in pdoc.
For example, the following results in the default value of 1 not showing up properly:
from pydantic import BaseModel
class Foo(BaseModel):
"""Test class."""
bar: int = Field(default=1)
Nor does the following:
from pydantic import BaseModel
class Foo(BaseModel):
"""Test class."""
bar: int = 1
Proposal
As "esoteric" as Pydantic can be at times, it would be nice to have native support for Pydantic models. Full-blown support for all of Pydantic is a heavy request, so I'd be happy with just supporting rendering default values properly (for the time being 😇).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two Pydantic model examples from the issue in pdoc and inspect how Pydantic model fields are rendered. Done means the default value specified with either Field(default=1) or a normal assignment is shown correctly in the generated documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100