Skip to content

Raise when unknown signals are connected to CallbackRegistries.#21238

Merged
tacaswell merged 1 commit intomatplotlib:mainfrom
anntzer:callbackrestrict
Feb 2, 2022
Merged

Raise when unknown signals are connected to CallbackRegistries.#21238
tacaswell merged 1 commit intomatplotlib:mainfrom
anntzer:callbackrestrict

Conversation

@anntzer
Copy link
Copy Markdown
Contributor

@anntzer anntzer commented Sep 30, 2021

I chose not to emit warnings during a deprecation period as otherwise
the semantics of the signals parameter would again have to change at
the end of the deprecation period (from warning to raising), which would
be another backcompatibility break...

Closes #8839.

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@anntzer anntzer added this to the v3.6.0 milestone Sep 30, 2021
Comment on lines +179 to +183
signals : list, optional
If not None, *signals* is a list of signals that this registry handles:
attempting to `process` or to `connect` to a signal not in the list
throws a `ValueError`. The default, None, does not restrict the
handled signals.
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.

This is a very useful addition. Not being able to see easily which signals are available on a registry has always been a source of confusion and uncertainty to me.

Is there a reason signals is optional (other than backward compatibility)? If not, I propose to deprecate not specifying signals.

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.

backend_tools (MEP22) currently relies on being able to dynamically add signals. I'm not actually convinced that it's a good idea, but that's another discussion to have some other time...

Copy link
Copy Markdown
Member

@timhoffm timhoffm Oct 1, 2021

Choose a reason for hiding this comment

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

Can we have a private _register_signal() method for that case? Since CallbackRegistry is technically a public API, I'm in favor of changing the signal API only once.

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.

@tacaswell was also against that (#8839 (comment)). I personally don't have a very strong opinion either way, though (well, I think the whole CallbackRegistry API could be revisited, but that's another discussion :-)).

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.

I'm not following the "not knowing is a feature" argument. It's comparable to adding attributes at runtime. It can be helpful in very specific cases, but in general it's rather confusing to not know the capabilities of an object.

Anyway, it's not important enough that I would block. If others want to approve as is that's fine for me.

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.

I mostly stand by my comment (I do not always agree with myself from 2017!), but I agree that not knowing what keys are supported can be very confusing and I really like the analogy to runtime adding attributes.

I would like to preserve the ability to have a any-to-any registry, I think having a "like known and warn on unknown" behavior is a bad mixed-state with the worst of both worlds.

I am in favor of making signals mandatory eventually with the ability to pass None to get the naive dispatcher.

I think adding a (public) API to manage the known signals is also a good idea.

I chose not to emit warnings during a deprecation period as otherwise
the semantics of the `signals` parameter would again have to change at
the end of the deprecation period (from warning to raising), which would
be another backcompatibility break...
@jklymak jklymak requested a review from dstansby February 1, 2022 11:55
@jklymak
Copy link
Copy Markdown
Member

jklymak commented Feb 1, 2022

@dstansby you originally suggested this be fixed - any bandwidth to review this? Thanks!

Copy link
Copy Markdown
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

I still think that signals should be mandatory in the long run, but as a first step and considering compatibility, starting optional is ok.

@tacaswell tacaswell merged commit b989a67 into matplotlib:main Feb 2, 2022
@tacaswell
Copy link
Copy Markdown
Member

Merged to keep the perfect of being the enemy of the good.

@anntzer anntzer deleted the callbackrestrict branch February 2, 2022 23:45
@dstansby
Copy link
Copy Markdown
Member

dstansby commented Feb 7, 2022

Thanks for this!

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.

mpl_connect silently does nothing when passed an invalid event type string

6 participants