2023-02-23 13:37:34 -08:00
|
|
|
from typing import Self
|
2020-07-22 02:45:16 -07:00
|
|
|
import copy
|
|
|
|
|
|
|
|
|
2024-07-28 20:18:12 -07:00
|
|
|
class Copyable:
|
2020-07-22 02:45:16 -07:00
|
|
|
"""
|
2023-04-07 23:19:55 -07:00
|
|
|
Trait class which adds .copy() and .deepcopy()
|
2020-07-22 02:45:16 -07:00
|
|
|
"""
|
|
|
|
__slots__ = ()
|
|
|
|
|
2023-04-07 23:19:55 -07:00
|
|
|
#
|
|
|
|
# Non-abstract methods
|
|
|
|
#
|
2023-02-23 13:37:34 -08:00
|
|
|
def copy(self) -> Self:
|
2020-07-22 02:45:16 -07:00
|
|
|
"""
|
|
|
|
Return a shallow copy of the object.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
`copy.copy(self)`
|
|
|
|
"""
|
|
|
|
return copy.copy(self)
|
|
|
|
|
2023-02-23 13:37:34 -08:00
|
|
|
def deepcopy(self) -> Self:
|
2020-07-22 02:45:16 -07:00
|
|
|
"""
|
|
|
|
Return a deep copy of the object.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
`copy.deepcopy(self)`
|
|
|
|
"""
|
|
|
|
return copy.deepcopy(self)
|