Skip to content
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

Rename skip-defaults, and add ability to exclude actual defaults #915

Merged
merged 6 commits into from
Oct 23, 2019

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented Oct 21, 2019

Change Summary

Rename skip_defaults to exclude_unset, and add exclude_defaults argument.

Still need to add tests and docs, but I wanted to get some feedback on the approach first.

Related issue number

fix #523

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)

@codecov
Copy link

codecov bot commented Oct 21, 2019

Codecov Report

Merging #915 into master will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff          @@
##           master   #915   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          16     16           
  Lines        2799   2799           
  Branches      543    543           
=====================================
  Hits         2799   2799

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f5cde39...1c64181. Read the comment docs.

pydantic/main.py Show resolved Hide resolved
pydantic/main.py Show resolved Hide resolved
docs/usage/exporting_models.md Show resolved Hide resolved
pydantic/main.py Show resolved Hide resolved
pydantic/main.py Outdated
@@ -345,8 +358,20 @@ def json(

`encoder` is an optional function to supply as `default` to json.dumps(), other arguments as per `json.dumps()`.
"""
if skip_defaults is not None:
warnings.warn(
f'{type(self).__name__}.dict: "skip_defaults" is deprecated and replaced by "exclude_unset"',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f'{type(self).__name__}.dict: "skip_defaults" is deprecated and replaced by "exclude_unset"',
f'{type(self).__name__}.json: "skip_defaults" is deprecated and replaced by "exclude_unset"',

?

pydantic/main.py Show resolved Hide resolved
pydantic/main.py Outdated Show resolved Hide resolved
pydantic/main.py Outdated Show resolved Hide resolved
@samuelcolvin
Copy link
Member

need tests for the warning raise by skip_defaults and that it does the same thing as exclude_defaults

@samuelcolvin
Copy link
Member

also need a change file.

@samuelcolvin
Copy link
Member

I think this is the only thing v1 is waiting for. If possible it would be great if this could get finished.

Otherwise hope you don't if I push to this PR to finish it tomorrow.

@samuelcolvin samuelcolvin merged commit 6b5adcc into pydantic:master Oct 23, 2019
@samuelcolvin
Copy link
Member

awesome, thank you.

andreshndz pushed a commit to cuenca-mx/pydantic that referenced this pull request Jan 17, 2020
…antic#915)

* Rename skip-defaults, and add ability to exclude actual defaults

* Add __defaults__ and deprecation warnings

* Add note about `skip_defaults` to docs

* Incorporate feedback

* Add tests and changes

* Fix reference to .json()
alexdrydew pushed a commit to alexdrydew/pydantic that referenced this pull request Dec 23, 2023
elliotgunton added a commit to argoproj-labs/hera that referenced this pull request Sep 27, 2024
**Description of PR**
Currently, we are setting both `skip_defaults` and `exclude_unset` when
we call Pydantic's `json` method. The former was made a (deprecated)
alias for the latter in pydantic/pydantic#915,
released [as part of
v1.0](https://github.com/pydantic/pydantic/blob/main/HISTORY.md#v10-2019-10-23);
we have a minimum requirement of v1.7.

This PR removes the redundant `skip_defaults` parameter.

Signed-off-by: Alice Purcell <[email protected]>
Co-authored-by: Elliot Gunton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dict(skip_defaults=True) doesn't apply to nested models
2 participants