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

Skip to content

Commit f765d04

Browse files
committed
Use builtin copy for shallow copy
1 parent 191452d commit f765d04

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

lib/matplotlib/path.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
visualisation.
1010
"""
1111

12+
import copy
1213
from functools import lru_cache
1314
from weakref import WeakValueDictionary
1415

@@ -259,20 +260,12 @@ def readonly(self):
259260
"""
260261
return self._readonly
261262

262-
def __copy__(self):
263+
def copy(self):
263264
"""
264265
Return a shallow copy of the `Path`, which will share the
265266
vertices and codes with the source `Path`.
266267
"""
267-
try:
268-
codes = self.codes
269-
except AttributeError:
270-
codes = None
271-
return self.__class__(
272-
self.vertices, codes,
273-
_interpolation_steps=self._interpolation_steps)
274-
275-
copy = __copy__
268+
return copy.copy(self)
276269

277270
def __deepcopy__(self, memo=None):
278271
"""
@@ -288,7 +281,7 @@ def __deepcopy__(self, memo=None):
288281
_interpolation_steps=self._interpolation_steps)
289282

290283
deepcopy = __deepcopy__
291-
284+
292285
@classmethod
293286
def make_compound_path_from_polys(cls, XY):
294287
"""

lib/matplotlib/tests/test_path.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ def test_path_deepcopy():
334334
path2 = Path(verts, codes)
335335
path1_copy = path1.deepcopy()
336336
path2_copy = path2.deepcopy()
337-
assert(path1 is not path1_copy)
338-
assert(path1.vertices is not path1_copy.vertices)
339-
assert(path2 is not path2_copy)
340-
assert(path2.vertices is not path2_copy.vertices)
341-
assert(path2.codes is not path2_copy.codes)
337+
assert path1 is not path1_copy
338+
assert path1.vertices is not path1_copy.vertices
339+
assert path2 is not path2_copy
340+
assert path2.vertices is not path2_copy.vertices
341+
assert path2.codes is not path2_copy.codes
342342

343343

344344
def test_path_shallowcopy():
@@ -349,11 +349,11 @@ def test_path_shallowcopy():
349349
path2 = Path(verts, codes)
350350
path1_copy = path1.copy()
351351
path2_copy = path2.copy()
352-
assert(path1 is not path1_copy)
353-
assert(path1.vertices is path1_copy.vertices)
354-
assert(path2 is not path2_copy)
355-
assert(path2.vertices is path2_copy.vertices)
356-
assert(path2.codes is path2_copy.codes)
352+
assert path1 is not path1_copy
353+
assert path1.vertices is path1_copy.vertices
354+
assert path2 is not path2_copy
355+
assert path2.vertices is path2_copy.vertices
356+
assert path2.codes is path2_copy.codes
357357

358358

359359
@pytest.mark.parametrize('phi', np.concatenate([

0 commit comments

Comments
 (0)