-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 smart_deepcopy (originaly from #1679) #1920
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1920 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 21
Lines 3909 3916 +7
Branches 788 788
=========================================
+ Hits 3909 3916 +7
Continue to review full report at Codecov.
|
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.
Nice !
Co-authored-by: PrettyWood <em.jolibois@gmail.com>
Obj = TypeVar('Obj') | ||
|
||
|
||
def smart_deepcopy(obj: Obj) -> Obj: |
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.
Small food for thought that smart_deepcopy
seems not particularly descriptive about what this function does, but I cannot come up with a better name so just offering food for thought in case someone else has an idea 😅
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.
I also thought about «fast_deepcopy», but function is actually a bit slower in case it has to deepcopy value, so «smart» seemed a better choice.
I agree, it’s kinda vague word, so would love hear any better suggestions :)
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.
I agree with both, it's not a perfect name, but I can't think of anything better.
thanks so much, sorry I've taken so long to review this. |
I guess you can now update #1679 |
Change Summary
add
smart_deepcopy()
:It's primarily needed for faster copying of default values, since they're often are immutable types or empty collections
Here's benchmark showing the difference in speed between different types of values:
Related issue number
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)