From b923ef3a30688f37f5ac3a4ae1ed4a1a5224c7f3 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 1 May 2020 20:04:42 +0200 Subject: [PATCH] Simplify pickling support. - silent_list is directly picklable as is; no need to do anything about it. While we're at it, also get rid of `__str__` -- `__str__` is documented to fall back on `__repr__`, so the latter is sufficient. - When pickling GridSpec and SubplotSpec, set _layoutbox to None, so that no special loading is needed. --- lib/matplotlib/cbook/__init__.py | 10 ---------- lib/matplotlib/gridspec.py | 24 ++---------------------- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 57fe140da7bf..f2cd3660bfe7 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -256,16 +256,6 @@ def __init__(self, type, seq=None): def __repr__(self): return '' % (len(self), self.type) - __str__ = __repr__ - - def __getstate__(self): - # store a dictionary of this SilentList's state - return {'type': self.type, 'seq': self[:]} - - def __setstate__(self, state): - self.type = state['type'] - self.extend(state['seq']) - @deprecated("3.3") class IgnoredKeywordWarning(UserWarning): diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index b2d7c1c8806a..b25bfe853534 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -312,17 +312,7 @@ def __init__(self, nrows, ncols, figure=None, _AllowedKeys = ["left", "bottom", "right", "top", "wspace", "hspace"] def __getstate__(self): - state = self.__dict__ - try: - state.pop('_layoutbox') - except KeyError: - pass - return state - - def __setstate__(self, state): - self.__dict__ = state - # layoutboxes don't survive pickling... - self._layoutbox = None + return {**self.__dict__, "_layoutbox": None} def update(self, **kwargs): """ @@ -580,17 +570,7 @@ def num2(self, value): self._num2 = value def __getstate__(self): - state = self.__dict__ - try: - state.pop('_layoutbox') - except KeyError: - pass - return state - - def __setstate__(self, state): - self.__dict__ = state - # layoutboxes don't survive pickling... - self._layoutbox = None + return {**self.__dict__, "_layoutbox": None} def get_gridspec(self): return self._gridspec