8000 Remove extra loop from disconnect · matplotlib/matplotlib@baca32b · GitHub
[go: up one dir, main page]

Skip to content
< 10000 header data-hidden="false" class="prc-PageLayout-Header-mQXK1" style="--spacing:var(--spacing-none)">

Commit baca32b

Browse files
committed
Remove extra loop from disconnect
1 parent f35521a commit baca32b

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,20 @@ def disconnect(self, cid):
230230
231231
No error is raised if such a callback does not exist.
232232
"""
233-
for eventname, callbackd in list(self.callbacks.items()):
234-
try:
235-
del callbackd[cid]
236-
except KeyError:
237-
continue
238-
else:
239-
for signal, functions in list(self._func_cid_map.items()):
240-
for function, value in list(functions.items()):
241-
if value == cid:
242-
del functions[function]
243-
return
233+
# Clean up callbacks
234+
for signal, cid_to_proxy in list(self.callbacks.items()):
235+
proxy = cid_to_proxy.pop(cid, None)
236+
if proxy is not None:
237+
break
238+
else:
239+
# Not found
240+
return
241+
242+
proxy_to_cid = self._func_cid_map[signal]
243+
for current_proxy, current_cid in list(proxy_to_cid.items()):
244+
if current_cid == cid:
245+
assert proxy is current_proxy
246+
del proxy_to_cid[current_proxy]
244247

245248
def process(self, s, *args, **kwargs):
246249
"""

0 commit comments

Comments
 (0)
0