Explicit registration of canvas-specific tool subclasses.#20990
Merged
fariza merged 1 commit intomatplotlib:masterfrom Sep 14, 2021
Merged
Explicit registration of canvas-specific tool subclasses.#20990fariza merged 1 commit intomatplotlib:masterfrom
fariza merged 1 commit intomatplotlib:masterfrom
Conversation
Member
|
Does the example still works? |
Contributor
Author
|
Yes, it works. |
fariza
reviewed
Sep 8, 2021
| _tool_registry = set() | ||
|
|
||
|
|
||
| def _register_tool_class(canvas_cls, tool_cls=None): |
Member
There was a problem hiding this comment.
I don't see how to do it easily, but I still need to ask, is it possible to add test to these two functions?
Contributor
Author
There was a problem hiding this comment.
They are covered already by existing tests (https://codecov.io/gh/matplotlib/matplotlib/compare/971d1106464560038151bf79d032515cd843b149...49d855f552bb44282b40ff689c5de5fe60ffbc15/diff).
fariza
approved these changes
Sep 13, 2021
Member
|
@anntzer does it need a rebase? |
Don't mess up with overwriting backend_tools globals, which would fail if multiple backend modules are imported.
Contributor
Author
|
rebased |
Contributor
Author
|
Please note that the standard policy is two positive reviews before merging. |
Member
|
Sorry, I saw Github requesting only one review, and I saw this as kind of small well contained change |
tacaswell
pushed a commit
that referenced
this pull request
Oct 20, 2021
Explicit registration of canvas-specific tool subclasses.
This was referenced Apr 12, 2023
Closed
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.
Don't mess up with overwriting backend_tools globals, which would fail if multiple backend modules are imported.
This proposes an API to fix #17986 (and therefore unblock #20273 (comment)). I had tried another approach back in #9941, but that PR did many more cleanups at the same time and therefore got bogged down in side discussions; this one solely implements canvas-specific tool subclass registration. That registration mechanism is private for now, but we can always consider making it public if there's demand for it. (I actually guess there would not be that much demand for third-party tool implementers because even if the tool really required some backend-specific logic, it could just use a plain old if-switch instead (https://github.com/anntzer/mplinorm/blob/dbd0b34ab4b2ad3799410565ec6ad31f992b7576/lib/mplinorm.py#L162) because a single module/package would provide the tools; the dispatch problem on Matplotlib's side mostly comes from the fact that each backend implements its own tools in its own module. The only case where this would really be necessary for third parties is for integration into a new event loop.)
(See the linked PRs and issues for more details about the problem this is solving.)
attn @fariza, I guess.
PR Summary
PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsand runflake8 --docstring-convention=all).doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).