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
Add defaults.deepcopy function. #44851
Conversation
Nice idea. This jinja2 example is more efficient?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks useful for jinja scenarios. thanks!!
Nope, that's actually the current behavior with normal copy because The defaults will be overwritten within 1st iteration. Here is an example:
That's why it should make a real copy inside the loop. |
Thanks for the clear explanation!! @aabouzaid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tests, too. 👍
@aabouzaid It looks like your new test isn't passing though. Can you take another look? |
@rallytime a typo 🙆♂️ |
What does this PR do?
Expose
copy.deepcopy
asdefaults.deepcopy
function.What issues does this PR fix or reference?
In many case there are multi level of defaults, e.g. global, group, and specific.
And since Python does not copy objects by default but creates bindings, so deep copy is necessary for that cases.
Here is an arbitrary example:
Yaml
Jinja
Output
New Behavior
Allow to make deepcopy of objects.
Tests written?
Yes
Commits signed with GPG?
Not yet.