Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e68b16

Browse files
authored
Merge pull request #17297 from anntzer/getstate
Simplify pickling support.
2 parents d1be9ad + b923ef3 commit 1e68b16

File tree

2 files changed

+2
-32
lines changed

2 files changed

+2
-32
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,6 @@ def __init__(self, type, seq=None):
256256
def __repr__(self):
257257
return '<a list of %d %s objects>' % (len(self), self.type)
258258

259-
__str__ = __repr__
260-
261-
def __getstate__(self):
262-
# store a dictionary of this SilentList's state
263-
return {'type': self.type, 'seq': self[:]}
264-
265-
def __setstate__(self, state):
266-
self.type = state['type']
267-
self.extend(state['seq'])
268-
269259

270260
@deprecated("3.3")
271261
class IgnoredKeywordWarning(UserWarning):

lib/matplotlib/gridspec.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -312,17 +312,7 @@ def __init__(self, nrows, ncols, figure=None,
312312
_AllowedKeys = ["left", "bottom", "right", "top", "wspace", "hspace"]
313313

314314
def __getstate__(self):
315-
state = self.__dict__
316-
try:
317-
state.pop('_layoutbox')
318-
except KeyError:
319-
pass
320-
return state
321-
322-
def __setstate__(self, state):
323-
self.__dict__ = state
324-
# layoutboxes don't survive pickling...
325-
self._layoutbox = None
315+
return {**self.__dict__, "_layoutbox": None}
326316

327317
def update(self, **kwargs):
328318
"""
@@ -580,17 +570,7 @@ def num2(self, value):
580570
self._num2 = value
581571

582572
def __getstate__(self):
583-
state = self.__dict__
584-
try:
585-
state.pop('_layoutbox')
586-
except KeyError:
587-
pass
588-
return state
589-
590-
def __setstate__(self, state):
591-
self.__dict__ = state
592-
# layoutboxes don't survive pickling...
593-
self._layoutbox = None
573+
return {**self.__dict__, "_layoutbox": None}
594574

595575
def get_gridspec(self):
596576
return self._gridspec

0 commit comments

Comments
 (0)