File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import copy
34import operator
45
56from datetime import date
67from datetime import datetime
78from datetime import timedelta
89from typing import TYPE_CHECKING
10+ from typing import Any
911from typing import Generic
1012from typing import TypeVar
1113from typing import cast
@@ -409,3 +411,10 @@ def __eq__(self, other: object) -> bool:
409411
410412 def __ne__ (self , other : object ) -> bool :
411413 return not self .__eq__ (other )
414+
415+ def __deepcopy__ (self , memo : dict [int , Any ]) -> Self :
416+ return self .__class__ (
417+ copy .deepcopy (self .start , memo ),
418+ copy .deepcopy (self .end , memo ),
419+ self ._absolute ,
420+ )
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import copy
34import pickle
45
56from datetime import timedelta
@@ -65,3 +66,18 @@ def test_inequality():
6566
6667 assert interval1 != interval2
6768 assert interval1 != interval3
69+
70+
71+ def test_deepcopy ():
72+ dt1 = pendulum .datetime (2016 , 11 , 18 )
73+ dt2 = pendulum .datetime (2016 , 11 , 20 )
74+
75+ interval = dt2 - dt1
76+
77+ interval2 = copy .deepcopy (interval )
78+
79+ assert interval == interval2
80+ # make sure it's a deep copy
81+ assert interval is not interval2
82+ assert interval .start is not interval2 .start
83+ assert interval .end is not interval2 .end
You can’t perform that action at this time.
0 commit comments