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

Fix/deep copy recurse #29393

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 3 commits into
base: main
Choose a base branch
Loading
from
Open
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
20 changes: 18 additions & 2 deletions 20 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,26 @@
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)
assert memo is not None
p = _reconstruct(self, memo, *rv)

Check warning on line 289 in lib/matplotlib/path.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/path.py#L286-L289

Added lines #L286 - L289 were not covered by tests
if memo is not None:
memo[id(self)] = p
_keep_alive(self, memo)

Check warning on line 292 in lib/matplotlib/path.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/path.py#L291-L292

Added lines #L291 - L292 were not covered by tests

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 8 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 @@ -140,7 +141,12 @@
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)

Check warning on line 147 in lib/matplotlib/transforms.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/transforms.py#L145-L147

Added lines #L145 - L147 were not covered by tests
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
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.