You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched Google & GitHub for similar requests and couldn't find anything
I have read and followed the docs and still think this feature is missing
Description
My usecase:
I have multiple Models with hundreds of fields each, I would like to have a repr of the Models with only some of the fields without having to override the __repr__ created by Pydantic. I could indeed set each field to be Field(repr=False) and keep the default repr=True to those that I need, but this approach sounds very labour intensive and counter productive.
Instead I think the Model should have a switch in ConfigDict to set the default of the repr field of each Field.
Thanks for the detailed feature request. I do have a general concern about the increased bloating of the config settings, and I don't feel as though this one is super high priority.
That being said, if you're interested in submitting a PR adding support for this, we can certainly consider it!
Initial Checks
Description
My usecase:
I have multiple Models with hundreds of fields each, I would like to have a
repr
of the Models with only some of the fields without having to override the__repr__
created by Pydantic. I could indeed set each field to beField(repr=False)
and keep the defaultrepr=True
to those that I need, but this approach sounds very labour intensive and counter productive.Instead I think the Model should have a switch in
ConfigDict
to set the default of therepr
field of eachField
.So in
pydantic/fields.py
instead of havingYou would have something like:
With this approach then you will have:
And only
x
will be in the model. If noField
is configured withrepr=True
then it can either be an emptyrepr
like:or the standard python
repr
like:This feature I think would significantly simplify the management of model representations, especially for large models with numerous fields.
Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: