Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a9f8dae

Browse filesBrowse files
committed
FIX: account for changes to cpython with copy/deepcopy to super()
See python/cpython#126817 for upstream discussion. This works around the change by using (private) methods from the copy module to re-implement the path though copy/deepcopy that we would like to use but avoid the special-casing for `super()` objects that is breaking us. We could vendor the current versions of `_keep_alive` (weakref work to manage lifecycles) and `_reconstruct` (where the recursion happens) to superficially avoid using private functions from CPython. However, if these functions do change significantly I worry that our copies would not inter-operate anyway. Closes #29157
1 parent e947dbc commit a9f8dae
Copy full SHA for a9f8dae

File tree

2 files changed

+19
-2
lines changed
Filter options

2 files changed

+19
-2
lines changed

‎lib/matplotlib/path.py

Copy file name to clipboardExpand all lines: lib/matplotlib/path.py
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import copy
1313
from functools import lru_cache
14+
import sys
1415
from weakref import WeakValueDictionary
1516

1617
import numpy as np
@@ -281,7 +282,17 @@ def __deepcopy__(self, memo=None):
281282
readonly, even if the source `Path` is.
282283
"""
283284
# Deepcopying arrays (vertices, codes) strips the writeable=False flag.
284-
p = copy.deepcopy(super(), memo)
285+
if sys.version_info >= (3, 14):
286+
from copy import _reconstruct, _keep_alive
287+
rv = super().__reduce_ex__(4)
288+
assert memo is not None
289+
p = _reconstruct(self, memo, *rv)
290+
if memo is not None:
291+
memo[id(self)] = p
292+
_keep_alive(self, memo)
293+
294+
else:
295+
p = copy.deepcopy(super(), memo)
285296
p._readonly = False
286297
return p
287298

‎lib/matplotlib/transforms.py

Copy file name to clipboardExpand all lines: lib/matplotlib/transforms.py
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import copy
3939
import functools
4040
import itertools
41+
import sys
4142
import textwrap
4243
import weakref
4344
import math
@@ -140,7 +141,12 @@ def __setstate__(self, data_dict):
140141
for k, v in self._parents.items() if v is not None}
141142

142143
def __copy__(self):
143-
other = copy.copy(super())
144+
if sys.version_info >= (3, 14):
145+
from copy import _reconstruct
146+
rv = super().__reduce_ex__(4)
147+
other = _reconstruct(self, None, *rv)
148+
else:
149+
other = copy.copy(super())
144150
# If `c = a + b; a1 = copy(a)`, then modifications to `a1` do not
145151
# propagate back to `c`, i.e. we need to clear the parents of `a1`.
146152
other._parents = {}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.