mitmproxy / mitmproxy/pdoc

Support default values specified in Pydantic Models

Open
#793 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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)
Image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.