Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import copy
from functools import lru_cache
import sys
from weakref import WeakValueDictionary

import numpy as np
Expand Down Expand Up @@ -281,11 +282,25 @@ def __deepcopy__(self, memo=None):
readonly, even if the source `Path` is.
"""
# Deepcopying arrays (vertices, codes) strips the writeable=False flag.
p = copy.deepcopy(super(), memo)
if sys.version_info >= (3, 14):
from copy import _reconstruct, _keep_alive
rv = super().__reduce_ex__(4)
p = _reconstruct(self, memo, *rv)
if memo is not None:
memo[id(self)] = p
_keep_alive(self, memo)

else:
p = copy.deepcopy(super(), memo)
p._readonly = False
return p

deepcopy = __deepcopy__
def deepcopy(self, memo=None):
"""
Return a deep copy of the `Path`, with copies of the
vertices and codes with the source `Path`.
"""
return copy.deepcopy(self, memo=memo)

@classmethod
def make_compound_path_from_polys(cls, XY):
Expand Down
8 changes: 7 additions & 1 deletion lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import copy
import functools
import itertools
import sys
import textwrap
import weakref
import math
Expand Down Expand Up @@ -139,7 +140,12 @@ def __setstate__(self, data_dict):
for k, v in self._parents.items() if v is not None}

def __copy__(self):
other = copy.copy(super())
if sys.version_info >= (3, 14):
from copy import _reconstruct
rv = super().__reduce_ex__(4)
other = _reconstruct(self, None, *rv)
else:
other = copy.copy(super())
# If `c = a + b; a1 = copy(a)`, then modifications to `a1` do not
# propagate back to `c`, i.e. we need to clear the parents of `a1`.
other._parents = {}
Expand Down