Skip to content

allow passing a function to CallbackRegistry.disconnect_func - #30844

Merged
ksunden merged 6 commits into
matplotlib:mainfrom
ianhi:callback-disconnect
Mar 6, 2026
Merged

ksunden merged 6 commits into
matplotlib:mainfrom
ianhi:callback-disconnect

Conversation

@ianhi

@ianhi ianhi commented Dec 12, 2025 •

Copy link
Copy Markdown
Contributor

PR summary

Make it more convenient to disconnect a callback by allowing passing back the function instead of requiring keeping track of the callback_id.

  • I added a new function instead of overloading the arguments to the existing disconnect because I felt it would get to complicated
  • I also updated disconnect to re-use the duplicated logic in _remove_proxy

I'm not 100% on the naming, but that is apparently what I thought was good in 2022, so trusting prior me.

Closes: #23306

AI 🤖 : Ideas all mine, actual code changes by claude. I have reviewed every changed line

PR checklist

@ianhi

ianhi commented Dec 12, 2025

Copy link
Copy Markdown
Contributor Author

The failing tests seem unrelated?

@timhoffm

timhoffm commented Dec 13, 2025 •

Copy link
Copy Markdown
Member

Would it make sense to fold this into the existing disconnect() method? So that you can do

disconnect(cid)
disconnect(func)  #from all events

And an one of these for event-specific disconnecting

disconnect(func, event=event)
disconnect((event, func))

API-wise this feels more intuitive than a separate function. If the implementation gets too messy, you should be able to dispatch to a helper function based on the parameters.

@ianhi

ianhi commented Dec 13, 2025

Copy link
Copy Markdown
Contributor Author

That's a nice suggestion. I have implemented it.

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modulo fixing the change notes.

Comment on lines +8 to +9
``CallbackRegistry.disconnect_func`` has been removed; use
``disconnect(func, signal=...)`` instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove. Was this pedantic AI 😄 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aghh. that's embarassing. indeed.

The aggressive back compatibility from changes within a session has to be one of my least favorite aspects of AI code tools

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianhi Since you've been systematically using AI on our codebase, maybe you are interested or can give input to
#30848

@@ -0,0 +1,20 @@
``CallbackRegistry.disconnect_func`` to disconnect callbacks by function

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops forgot to update this whats new with the most recent changes.

Are you saying that this should no longer get a whatsnews, or just I should update it to use disconnect?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, update is the correct way.

@ksunden
ksunden merged commit d3f5e11 into matplotlib:main Mar 6, 2026
36 of 37 checks passed
@ksunden ksunden added this to the v3.11.0 milestone Mar 6, 2026
@ianhi
ianhi deleted the callback-disconnect branch March 6, 2026 21:16
andreas16700 added a commit to andreas16700/matplotlib that referenced this pull request Mar 16, 2026
andreas16700 added a commit to andreas16700/matplotlib that referenced this pull request Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: allow passing a function to CallbackRegistry.disconnect

3 participants