Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jkseppan
Copy link
Member

@jkseppan jkseppan commented Jun 21, 2025

Give it a metaclass that lets us remove the __deepcopy__ method
from sight when executing that method.

Closes #29157 without relying on private CPython methods.

There is a separate fix for the other issue with TransformNode.__copy__.

PR summary

PR checklist

Give it a metaclass that lets us remove the __deepcopy__ method
from sight when executing that method.

Closes matplotlib#29157 without relying on private CPython methods.
Does not fix the other issue with TransformNode.__copy__.
@jkseppan jkseppan force-pushed the path-deepcopy-via-metaclass branch from 54ac172 to 996b647 Compare June 21, 2025 07:10
@jkseppan jkseppan force-pushed the path-deepcopy-via-metaclass branch from fa7ed8b to 68d25b3 Compare June 21, 2025 08:00
@jkseppan jkseppan requested a review from tacaswell June 21, 2025 08:56
@jkseppan
Copy link
Member Author

jkseppan commented Jun 21, 2025

I tried the same strategy with TransformNode.__copy__ but copy.copy looks at getattr(cls, "__copy__", None) so we'd need to override attribute lookup on the class and not its instances, and then we can't have an instance-specific flag.

EDIT: this is actually easier to fix by just doing the shallow copy without copy.copy

without calling copy.copy
No reason to look up __deepcopy__ in base classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FUTURE BUG: reconsider how we deep-copy path objects
1 participant