Skip to content

feature: greater distinction for model ClassVar #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
awgymer opened this issue Jan 3, 2025 · 1 comment
Open

feature: greater distinction for model ClassVar #18

awgymer opened this issue Jan 3, 2025 · 1 comment
Assignees
Labels
feature New feature or request

Comments

@awgymer
Copy link

awgymer commented Jan 3, 2025

This is a really neat extension which gives a nice output.

One thing which would be very nice to have is for any ClassVar on a model to be grouped separately or otherwise indicated in the list of attributes.

Currently it also shows pydantic-field for such a field when you set show_labels: true but this is misleading as a value set as ClassVar is not validated as part of the model!

A model example to recreate this:

class MyModelWithClassVar(BaseModel):
    """This is an example model with a `ClassVar`"""

    model_config = ConfigDict(extra="allow", use_enum_values=True)

    TOP_SECRET: ClassVar[str] = "BASE"
    """This is a ClassVar"""
    a: int
    """This is a model field"""
    b: str
    """This is also a model field"""

    @field_validator("a")
    @classmethod
    def check_a_is_big(cls, v: int, info: ValidationInfo) -> int:
        if v < 10:
            raise ValueError("a is too small!")
        return v

And this gives:
image

@awgymer awgymer added the feature New feature or request label Jan 3, 2025
@pawamoy
Copy link
Member

pawamoy commented Jan 3, 2025

Hi @awgymer, thanks for the request, and for the kind words ❤️

Noted, added to the backlog!

@pawamoy pawamoy added the fund Issue priority can be boosted label Jan 3, 2025
mmzeynalli added a commit to mmzeynalli/griffe-pydantic that referenced this issue Feb 12, 2025
ClassVar is shown as `pydantic-field` right now, this commit fixes it,
and shows `pydantic-classvar` instead of it.

Issue mkdocstrings#18: feature: greater distinction for model `ClassVar`
pawamoy added a commit that referenced this issue Feb 17, 2025
Issue-18: #18
PR-25: #25
Co-authored-by: Timothée Mazzucotelli <[email protected]>
@pawamoy pawamoy removed the fund Issue priority can be boosted label Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants