Skip to content

Conversation

@art049
Copy link
Contributor

@art049 art049 commented Oct 28, 2020

Change Summary

While inheriting the configuration , the json_encoders dictionaries are merged and the child classes can still override an encoder defined in the parent class.

Related issue number

Fixes #2024

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)

@art049 art049 changed the title Implement merged json_encoders inheritance Add merged json_encoders inheritance Oct 28, 2020
@codecov
Copy link

codecov bot commented Oct 28, 2020

Codecov Report

Merging #2064 (3865c7b) into master (61bdba3) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##            master     #2064   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         4426      4426           
  Branches       888       888           
=========================================
  Hits          4426      4426           

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 61bdba3...3865c7b. Read the comment docs.

@art049 art049 force-pushed the json-encoders-inheritance branch from e6e61e7 to 904aeb9 Compare October 28, 2020 18:09
Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

you need to add a change description and update the docs to describe the new behaviour preferably with an example

pydantic/main.py Outdated
Comment on lines 168 to 184
json_encoders = {
**getattr(parent_config, 'json_encoders', {}),
**getattr(self_config, 'json_encoders', {}),
}
namespace['json_encoders'] = json_encoders
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
json_encoders = {
**getattr(parent_config, 'json_encoders', {}),
**getattr(self_config, 'json_encoders', {}),
}
namespace['json_encoders'] = json_encoders
namespace['json_encoders'] = {
**getattr(parent_config, 'json_encoders', {}),
**getattr(self_config, 'json_encoders', {}),
}

@art049
Copy link
Contributor Author

art049 commented Nov 29, 2020

you need to add a change description and update the docs to describe the new behaviour preferably with an example

Thanks for the feedback @samuelcolvin !
I wasn't very sure this feature was ok as I didn't have any feedback neither on the issue nor the PR so I didn't complete it but as it seems ok to you I will be happy complete the changes 😄

@samuelcolvin
Copy link
Member

@art049, I'm happy to accept this change.

We still need a change description and docs.

@PrettyWood PrettyWood added the awaiting author revision awaiting changes from the PR author label Jan 19, 2021
@samuelcolvin
Copy link
Member

@art049 are you okay to fix this?

@art049 art049 force-pushed the json-encoders-inheritance branch 2 times, most recently from 82e0990 to fd76fb6 Compare February 13, 2021 14:47
@art049 art049 force-pushed the json-encoders-inheritance branch 2 times, most recently from 6e00308 to 7039b05 Compare February 13, 2021 15:12
@art049
Copy link
Contributor Author

art049 commented Feb 13, 2021

@art049 are you okay to fix this?

@samuelcolvin yes, totally.
I fixed the code smell and added the required documentation 😄 .

WDYT about the docs? I don't know if it explains the feature properly enough

@art049 art049 force-pushed the json-encoders-inheritance branch from 7039b05 to 0b9ae26 Compare February 13, 2021 15:23
@art049 art049 force-pushed the json-encoders-inheritance branch from 0b9ae26 to 3865c7b Compare February 13, 2021 15:26
@samuelcolvin samuelcolvin merged commit 33c5a4d into pydantic:master Feb 13, 2021
@samuelcolvin
Copy link
Member

great, thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting author revision awaiting changes from the PR author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

json_encoders inheritance

3 participants