{{ message }}
Fix selectors when the onselect callback raises - #32349
Open
twelfthlabor wants to merge 1 commit into
Open
twelfthlabor wants to merge 1 commit into
twelfthlabor wants to merge 1 commit into
Conversation
`_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.
twelfthlabor
force-pushed
the
fix/spanselector-callback-exception-state
branch
from
September 13, 2026 06:14
8d69460 to
9b9dacf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

_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.