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

Skip to content

Commit 6464794

Browse files
committed
Make Path.__deepcopy__ interact better with subclasses, e.g. TextPath.
1 parent d297e41 commit 6464794

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/matplotlib/path.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,10 @@ def __deepcopy__(self, memo=None):
272272
Return a deepcopy of the `Path`. The `Path` will not be
273273
readonly, even if the source `Path` is.
274274
"""
275-
try:
276-
codes = self.codes.copy()
277-
except AttributeError:
278-
codes = None
279-
return self.__class__(
280-
self.vertices.copy(), codes,
281-
_interpolation_steps=self._interpolation_steps)
275+
# Deepcopying arrays (vertices, codes) strips the writeable=False flag.
276+
p = copy.deepcopy(super(), memo)
277+
p._readonly = False
278+
return p
282279

283280
deepcopy = __deepcopy__
284281

lib/matplotlib/tests/test_textpath.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import copy
2+
3+
from matplotlib.textpath import TextPath
4+
5+
6+
def test_copy():
7+
path = TextPath((0, 0), ".")
8+
copy.copy(path) # no error
9+
copy.deepcopy(path) # no error

0 commit comments

Comments
 (0)