Skip to content

Commit 1c03163

Browse files
authored
Merge pull request #19180 from timhoffm/fix-artist-remove-callback
Fix Artist.remove_callback()
2 parents 195030b + ae46b11 commit 1c03163

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/matplotlib/artist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def remove_callback(self, oid):
351351
--------
352352
add_callback
353353
"""
354-
self._callbacks.disconnect("pchanged", oid)
354+
self._callbacks.disconnect(oid)
355355

356356
def pchanged(self):
357357
"""

lib/matplotlib/tests/test_artist.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,21 @@ def test_set_alpha_for_array():
303303
art._set_alpha_for_array([0.5, 1.1])
304304
with pytest.raises(ValueError, match="alpha must be between 0 and 1"):
305305
art._set_alpha_for_array([0.5, np.nan])
306+
307+
308+
def test_callbacks():
309+
def func(artist):
310+
func.counter += 1
311+
312+
func.counter = 0
313+
314+
art = martist.Artist()
315+
oid = art.add_callback(func)
316+
assert func.counter == 0
317+
art.pchanged() # must call the callback
318+
assert func.counter == 1
319+
art.set_zorder(10) # setting a property must also call the callback
320+
assert func.counter == 2
321+
art.remove_callback(oid)
322+
art.pchanged() # must not call the callback anymore
323+
assert func.counter == 2

0 commit comments

Comments
 (0)