Repository navigation
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
| if memo is None: | ||
| memo = {} |
There was a problem hiding this comment.
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.
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.
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 <storchaka@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
without calling copy.copy
db1a305 to
5c7c915
Compare
QuLogic
left a comment
There was a problem hiding this comment.
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)
* matplotlib/matplotlib#30198: Python 3.14 compatible deepcopy. * What's New entry. * What's new line break. * Fix Sphinx bug with duplicated labels. * What's New addition. * Remove Python<3.14 pin from pyproject.toml; indicating compatibility, but not yet support (i.e. CI unchanged for now). * Better deepcopy docstring.
* matplotlib/matplotlib#30198: Python 3.14 compatible deepcopy. * Remove Python 3.14 pin. * Support Python 3.14. * Fix dumb versioning in test_python_versions. * Drop support for Python 3.11. * Update lock-files. * Removed `geovista` from py314 requirements. * pytest skips added to geovista experimental tests if import missing. * Refreshed lockfiles (no geovista in py314 lock) * Fixed lockfiles (were using JFrog Artifactory URL) * Added optional skips for doctests * Better geovista check in conf.py and reinstate missing doctest import * Updated whatsnew * Reference #6902 (reinstate goevista) in py314 YML file * Link `iris.yml` to `py314.yml` (and by association `readthedocs.yml`) --------- Co-authored-by: ukmo-ccbunney <christopher.bunney@metoffice.gov.uk> Co-authored-by: Chris Bunney <48915820+ukmo-ccbunney@users.noreply.github.com>
…#10702) ## 📝 Summary Closes #10680 `plots.py`, `dataflow.py`, and `markdown.py` under `marimo/_tutorials/` are pinned to `matplotlib==3.10.1`. That version hits an infinite recursion in `Path.__deepcopy__` when `_render_figure_mimebundle` calls `savefig(bbox_inches="tight")`, which forces a full draw pass under marimo's sandboxed edit mode. The recursion happens because `deepcopy`'s memo dict gets looked up via `super()` inside `Path.__deepcopy__`, and on the affected matplotlib version that lookup keeps recursing into itself instead of terminating. The fix for that recursion landed upstream in matplotlib/matplotlib#30198, and 3.10.9 already carries it. `sql.py` in the same directory is already on 3.10.9 and has never hit this, which is what pointed me at the fix in the first place. Bumping the three affected tutorials to `matplotlib==3.10.9` to match. ## 📋 Pre-Review Checklist - [x] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions. (See #10680, where this was reported and the fix was proposed and confirmed correct in the comments.) - [ ] Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it. - [ ] Video or media evidence is provided for any visual changes (optional). ## ✅ Merge Checklist - [x] I have read the contributor guidelines. - [x] Documentation has been updated where applicable, including docstrings for API changes. (Not applicable, this is a dependency pin change with no API surface.) - [ ] Tests have been added for the changes made. (Not applicable, this is a version pin bump in tutorial scripts, not a code change with new logic to test.)
…marimo-team#10702) ## 📝 Summary Closes marimo-team#10680 `plots.py`, `dataflow.py`, and `markdown.py` under `marimo/_tutorials/` are pinned to `matplotlib==3.10.1`. That version hits an infinite recursion in `Path.__deepcopy__` when `_render_figure_mimebundle` calls `savefig(bbox_inches="tight")`, which forces a full draw pass under marimo's sandboxed edit mode. The recursion happens because `deepcopy`'s memo dict gets looked up via `super()` inside `Path.__deepcopy__`, and on the affected matplotlib version that lookup keeps recursing into itself instead of terminating. The fix for that recursion landed upstream in matplotlib/matplotlib#30198, and 3.10.9 already carries it. `sql.py` in the same directory is already on 3.10.9 and has never hit this, which is what pointed me at the fix in the first place. Bumping the three affected tutorials to `matplotlib==3.10.9` to match. ## 📋 Pre-Review Checklist - [x] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions. (See marimo-team#10680, where this was reported and the fix was proposed and confirmed correct in the comments.) - [ ] Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it. - [ ] Video or media evidence is provided for any visual changes (optional). ## ✅ Merge Checklist - [x] I have read the contributor guidelines. - [x] Documentation has been updated where applicable, including docstrings for API changes. (Not applicable, this is a dependency pin change with no API surface.) - [ ] Tests have been added for the changes made. (Not applicable, this is a version pin bump in tutorial scripts, not a code change with new logic to test.)
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