You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Doc]: PyOS_InputHook documentation is incorrect #32314
Matplotlib does not currently do any management of PyOS_InputHook due to the wide range of ways that Matplotlib is used.
This has been incorrect since October 2023, when #26970 added a PyOS_InputHook function in the macOS backend. I'm not sure how we want to document this behavior.
I'll put in a quick fix for the docs, but given your work on overhauling the mac backend it is worth considering how to manage installing the hook better. One of the reasons we went with "just install it" is that to our understanding you could not use the old mac backend for embedding in bigger UIs so the range of other things people might have been doing was smaller so the "make it nice for the user in the prompt" seemed like a big upside with no downside.
The key distinction between the mac backend (and maybe webagg, but that has no reasonable shell story) and everything else is that we own the code from the python <-> toolkit binding where as with with everything else than binding comes from a dependency. In those case it is fair to expect someone else to do the hook management.
One of the reasons we went with "just install it" is that to our understanding you could not use the old mac backend for embedding in bigger UIs so the range of other things people might have been doing was smaller so the "make it nice for the user in the prompt" seemed like a big upside with no downside.
That makes sense, from my (still limited) understanding of how PyOS_InputHook works. What we should do is:
By default, install our PyOS_InputHook if we detect that we are also instantiating the NSApplication singleton and our own MPLAppDelegate. That's the "make it nice for the user in the prompt" default case.
If you are embedding us, we won't instantiate NSApplication, MPLAppDelegate, or touch PyOS_InputHook - although we could have an API that allows some control over this.
Activity
tacaswell commentedon Sep 9, 2026
Sigh, I both wrote those docs and merged that PR.
I'll put in a quick fix for the docs, but given your work on overhauling the mac backend it is worth considering how to manage installing the hook better. One of the reasons we went with "just install it" is that to our understanding you could not use the old mac backend for embedding in bigger UIs so the range of other things people might have been doing was smaller so the "make it nice for the user in the prompt" seemed like a big upside with no downside.
The key distinction between the mac backend (and maybe webagg, but that has no reasonable shell story) and everything else is that we own the code from the python <-> toolkit binding where as with with everything else than binding comes from a dependency. In those case it is fair to expect someone else to do the hook management.
iccir commentedon Sep 9, 2026
That makes sense, from my (still limited) understanding of how
PyOS_InputHookworks. What we should do is:PyOS_InputHookif we detect that we are also instantiating theNSApplicationsingleton and our ownMPLAppDelegate. That's the "make it nice for the user in the prompt" default case.NSApplication,MPLAppDelegate, or touchPyOS_InputHook- although we could have an API that allows some control over this.tacaswell commentedon Sep 9, 2026
That seems correct. We should also not clobber anything already installed.
Following the pattern of PyQt is probably the right model for any extra API we want to add.
DOC: correct note about PyOS_InputHook