File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -15,17 +15,21 @@ def test_set_size():
15
15
16
16
17
17
def test_deepcopy ():
18
- # Should not raise any error
19
18
path = TextPath ((0 , 0 ), "." )
20
19
path_copy = deepcopy (path )
21
20
assert isinstance (path_copy , TextPath )
22
21
assert path is not path_copy
23
22
assert path .vertices is not path_copy .vertices
24
23
assert path .codes is not path_copy .codes
24
+ path = TextPath ((0 , 0 ), "." )
25
+ path_copy = path .deepcopy ({})
26
+ assert isinstance (path_copy , TextPath )
27
+ assert path is not path_copy
28
+ assert path .vertices is not path_copy .vertices
29
+ assert path .codes is not path_copy .codes
25
30
26
31
27
32
def test_copy ():
28
- # Should not raise any error
29
33
path = TextPath ((0 , 0 ), "." )
30
34
path_copy = copy (path )
31
35
assert path is not path_copy
Original file line number Diff line number Diff line change
1
+ from copy import deepcopy
1
2
from collections import OrderedDict
2
3
import functools
3
4
import logging
@@ -429,3 +430,23 @@ def _revalidate_path(self):
429
430
self ._cached_vertices = tr .transform (self ._vertices )
430
431
self ._cached_vertices .flags .writeable = False
431
432
self ._invalid = False
433
+
434
+ def __deepcopy__ (self , memo ):
435
+ # taken from https://stackoverflow.com/a/15774013
436
+ self ._revalidate_path ()
437
+ cls = self .__class__
438
+ new_instance = cls .__new__ (cls )
439
+ memo [id (self )] = new_instance
440
+ for k , v in self .__dict__ .items ():
441
+ setattr (new_instance , k , deepcopy (v , memo ))
442
+ return new_instance
443
+
444
+ deepcopy = __deepcopy__
445
+
446
+ def __copy__ (self ):
447
+ # taken from https://stackoverflow.com/a/15774013
448
+ self ._revalidate_path ()
449
+ cls = self .__class__
450
+ new_instance = cls .__new__ (cls )
451
+ new_instance .__dict__ .update (self .__dict__ )
452
+ return new_instance
You can’t perform that action at this time.
0 commit comments