[wip] Replace _remove_method by _on_remove list of callbacks #10876
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
First commit replaces Artist._remove_method (called by Artist.remove) by a list of callbacks (with the same signature), Artist._on_remove.
Second commit shows the use case of such a change: it allows us to disconnect the dragging handlers when an artist is removed from an axes. An minimal example is the following:
and click on the annotation and try to drag it. As of master, this cause the following exception to be printed:
and this is fixed by the PR. (Note that clicking a second time would cause a different exception, independently of this PR, due to the fact that an artist cannot be removed twice.)
This may seem to be a slightly obscure case, but I have a real use case in https://github.com/anntzer/mplcursors: there, clicking on an artist will create an annotation on that artist, removing a previously created annotation (on another artist); then, moving the mouse would try to drag the now deleted annotation.
PR Checklist
Only touches private API.