Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0223e27

Browse filesBrowse files
authored
Merge pull request #7914 from anntzer/callbackregistry-unpickling
Fix unpickling of CallbackRegistry on Py2.
2 parents 23b93bd + ef3072e commit 0223e27
Copy full SHA for 0223e27

File tree

Expand file treeCollapse file tree

2 files changed

+14
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-4
lines changed

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,18 @@ def __init__(self):
291291
self._cid = 0
292292
self._func_cid_map = {}
293293

294+
# In general, callbacks may not be pickled; thus, we simply recreate an
295+
# empty dictionary at unpickling. In order to ensure that `__setstate__`
296+
# (which just defers to `__init__`) is called, `__getstate__` must
297+
# return a truthy value (for pickle protocol>=3, i.e. Py3, the
298+
# *actual* behavior is that `__setstate__` will be called as long as
299+
# `__getstate__` does not return `None`, but this is undocumented -- see
300+
# http://bugs.python.org/issue12290).
301+
294302
def __getstate__(self):
295-
# We cannot currently pickle the callables in the registry, so
296-
# return an empty dictionary.
297-
return {}
303+
return True
298304

299305
def __setstate__(self, state):
300-
# re-initialise an empty callback registry
301306
self.__init__()
302307

303308
def connect(self, s, func):

‎lib/matplotlib/tests/test_cbook.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_cbook.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33
import itertools
4+
import pickle
45
from weakref import ref
56
import warnings
67

@@ -283,6 +284,10 @@ def test_callback_complete(self):
283284
def dummy(self):
284285
pass
285286

287+
def test_pickling(self):
288+
assert hasattr(pickle.loads(pickle.dumps(cbook.CallbackRegistry())),
289+
"callbacks")
290+
286291

287292
def test_sanitize_sequence():
288293
d = {'a': 1, 'b': 2, 'c': 3}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.