Skip to content

Commit 9396ee7

Browse files
committed
Generate a unique cid for each (event_type, func) pair.
1 parent 1a9628e commit 9396ee7

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/matplotlib/cbook.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,21 @@ def __init__(self, *args):
243243
DeprecationWarning)
244244
self.callbacks = dict()
245245
self._cid = 0
246-
self._func_cid_map = WeakKeyDictionary()
246+
self._func_cid_map = {}
247247

248248
def connect(self, s, func):
249249
"""
250250
register *func* to be called when a signal *s* is generated
251251
func will be called
252252
"""
253-
if func in self._func_cid_map:
254-
cid = self._func_cid_map[func]
255-
else:
256-
self._cid += 1
257-
cid = self._cid
258-
self._func_cid_map[func] = cid
253+
self._func_cid_map.setdefault(s, WeakKeyDictionary())
254+
if func in self._func_cid_map[s]:
255+
return self._func_cid_map[s][func]
256+
257+
self._cid += 1
258+
cid = self._cid
259+
self._func_cid_map[s][func] = cid
259260
self.callbacks.setdefault(s, dict())
260-
if cid in self.callbacks[s]:
261-
return cid
262261
proxy = self.BoundMethodProxy(func)
263262
self.callbacks[s][cid] = proxy
264263
return cid
@@ -272,6 +271,8 @@ def disconnect(self, cid):
272271
del callbackd[cid]
273272
except KeyError:
274273
continue
274+
else:
275+
return
275276

276277
def process(self, s, *args, **kwargs):
277278
"""

0 commit comments

Comments
 (0)