feat: add exclude_none
parameter to model_dump_doc
#503
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR closes #504 issue.
Model example:
Demo:
Although in this example there is still an empty dictionary left, removing the key from it would also be good, but it distances itself from the
exclude_none
parameter.Maybe an
exclude_by_func
parameter would be ideal?This way, it is up to the user to choose the types of data (or even data) that should be excluded, however, it implies adding this feature to pydantic so that we can use it, or recreating
model_dump
from scratch.I created an issue on pydantic about this, I hope the idea is approved: pydantic/pydantic#10728