Fix selectors when the onselect callback raises - #32349
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
`_SelectorWidget.release` cleared `_eventpress` and `_eventrelease` only after `self._release(event)` returned, but `_release` is what calls the user's `onselect` callback. If that callback raised, the cleanup was skipped, and the stale `_eventpress` made `ignore` stop rejecting events outside the selector's Axes. The failed selector then kept reacting to later interactions, including events meant for another selector. Move the cleanup into a `finally` block so the exception still propagates while the selector stays usable afterwards. This covers all `_SelectorWidget` subclasses, which all call `onselect` from `_release`. Fixes matplotlib#32327.
8d69460 to
9b9dacf
Compare
_SelectorWidget.releasecleared_eventpressand_eventreleaseonly afterself._release(event)returned, but_releaseis what calls the user'sonselectcallback. If that callback raised, the cleanup was skipped, and the stale_eventpressmadeignore()stop rejecting events outside the selector's Axes. The failed selector then kept reacting to later interactions, including events meant for another selector.Move the cleanup into a
finallyblock so the exception still propagates while the selector stays usable afterwards. This covers all_SelectorWidgetsubclasses, which all callonselectfrom_release.Fixes #32327.
AI Disclosure
I used an AI coding assistant to help implement this change and write the tests. I reviewed the diff and verified the behavior locally.