-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement Path.__deepcopy__ avoiding infinite recursion #30198
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
Implement Path.__deepcopy__ avoiding infinite recursion #30198
Conversation
fa7ed8b
to
68d25b3
Compare
I tried the same strategy with EDIT: this is actually easier to fix by just doing the shallow copy without |
8258353
to
8fbb889
Compare
I changed this to remove the metaclass and implement the |
8fbb889
to
aa94dda
Compare
lib/matplotlib/path.py
Outdated
if memo is None: | ||
memo = {} |
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.
This is not needed, memo
is always a dict.
The default value for memo
is also not needed. The memo
argument is always passed to __deepcopy__()
.
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.
Yes, when called via copy.deepcopy
, but this __deepcopy__
method is also aliased to deepcopy
(just below the GitHub patch context) that is part of the public API of this class
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.
we could change our deepcopy to call copy.deepcopy
internally (which might bet better?)
2d93b8e
to
a76ab5a
Compare
To deep copy an object without calling deepcopy on the object itself, create a new object of the correct class and iterate calling deepcopy on its __dict__. Closes matplotlib#29157 without relying on private CPython methods. Does not fix the other issue with TransformNode.__copy__. Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Elliott Sales de Andrade <[email protected]>
without calling copy.copy
db1a305
to
5c7c915
Compare
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 tried this out on Fedora Rawhide with Python 3.14, and it worked.
…finite recursion
Thank you @jkseppan ! This is a better solution than my "reach up and touch private methods" version. |
…198-on-v3.10.x Backport PR #30198 on branch v3.10.x (Implement Path.__deepcopy__ avoiding infinite recursion)
Implement
Path.__deepcopy__
avoiding infinite recursionTo deep copy an object without calling deepcopy on the object itself, create a new object of the correct class and iterate calling deepcopy on its
__dict__
.Closes #29157 without relying on private CPython methods.
In a separate commit, fix the other issue with
TransformNode.__copy__
.PR summary
PR checklist