Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit d6d6ba4

Browse files
committed
Trac #31182: __getstate__ and __setstate__
1 parent d957f73 commit d6d6ba4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/sage/structure/mutability.pyx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ cdef class Mutability:
118118
"""
119119
return not self._is_immutable
120120

121+
def __getstate__(self):
122+
r"""
123+
Get the current state of ``self`` including the mutability status.
124+
"""
125+
state = getattr(self, '__dict__', {})
126+
state['_is_immutable'] = self._is_immutable
127+
return state
128+
129+
def __setstate__(self, state):
130+
r"""
131+
Set the state of ``self`` from the dictionary ``state`` including the
132+
mutability status.
133+
"""
134+
if hasattr(self, '__dict__'):
135+
self.__dict__ = state
136+
self._is_immutable = state['_is_immutable']
137+
121138
##########################################################################
122139
## Method decorators for mutating methods resp. methods that assume immutability
123140

0 commit comments

Comments
 (0)