Skip to content

Commit 4ec886d

Browse files
committed
Ensure connect() does not add duplicate callbacks. Fix if stmt.
1 parent 30f9def commit 4ec886d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/matplotlib/cbook.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ class _BoundMethodProxy(object):
361361
Minor bugfixes by Michael Droettboom
362362
'''
363363
def __init__(self, cb):
364+
self._hash = hash(cb)
364365
try:
365366
try:
366367
self.inst = ref(cb.im_self)
@@ -433,6 +434,9 @@ def __ne__(self, other):
433434
'''
434435
return not self.__eq__(other)
435436

437+
def __hash__(self):
438+
return self._hash
439+
436440

437441
class CallbackRegistry(object):
438442
"""
@@ -492,14 +496,14 @@ def connect(self, s, func):
492496
func will be called
493497
"""
494498
self._func_cid_map.setdefault(s, WeakKeyDictionary())
495-
if func in self._func_cid_map[s]:
496-
return self._func_cid_map[s][func]
499+
proxy = _BoundMethodProxy(func)
500+
if proxy in self._func_cid_map[s]:
501+
return self._func_cid_map[s][proxy]
497502

498503
self._cid += 1
499504
cid = self._cid
500-
self._func_cid_map[s][func] = cid
505+
self._func_cid_map[s][proxy] = cid
501506
self.callbacks.setdefault(s, dict())
502-
proxy = _BoundMethodProxy(func)
503507
self.callbacks[s][cid] = proxy
504508
return cid
505509

0 commit comments

Comments
 (0)