Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #31182: __getstate__ and __setstate__
Browse files Browse the repository at this point in the history
  • Loading branch information
mjungmath committed Jan 17, 2021
1 parent d957f73 commit d6d6ba4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/sage/structure/mutability.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ cdef class Mutability:
"""
return not self._is_immutable

def __getstate__(self):
r"""
Get the current state of ``self`` including the mutability status.
"""
state = getattr(self, '__dict__', {})
state['_is_immutable'] = self._is_immutable
return state

def __setstate__(self, state):
r"""
Set the state of ``self`` from the dictionary ``state`` including the
mutability status.
"""
if hasattr(self, '__dict__'):
self.__dict__ = state
self._is_immutable = state['_is_immutable']

##########################################################################
## Method decorators for mutating methods resp. methods that assume immutability

Expand Down

0 comments on commit d6d6ba4

Please sign in to comment.