Derive new_figure_manager from FigureCanvas.new_manager.#23090
Derive new_figure_manager from FigureCanvas.new_manager.#23090tacaswell merged 1 commit intomatplotlib:mainfrom
Conversation
timhoffm
left a comment
There was a problem hiding this comment.
For backcompat, the old codepath is maintained (and has priority).
In the long run (some years) we don't want to have two code paths. We should explicitly discourage the old way. But maybe that should be done when show() and draw_if_interactive()are there as well.
This should be documented somewhere. Do we have technical documentation how a backend works?
|
My plan was to first make all the changes, and then only document the full new API. I don't really think there's a reference doc of what an old-style backend must provide (closest is probably backend_template) and the point of this series of PR was also to make that documentation easier to write. I decided to start putting in these compat layers to show a bit the concrete end point before putting in more machinery for show and draw_if_interactive. Also note that there's actually a third way to define backends currently, namely via the |
timhoffm
left a comment
There was a problem hiding this comment.
Is it possible to test the logic?
|
Sure, found a way to do it which is a bit hacky, but heh... |
333cead to
fb33c71
Compare
jklymak
left a comment
There was a problem hiding this comment.
This seems fine to me, but maybe should get a double check from @tacaswell ?
|
BTW, seems if there will be a few of these they should get some label. I made one, but feel free to replace with something more appropriate or rename |
lib/matplotlib/pyplot.py
Outdated
| draw_if_interactive = getattr(backend_mod, "draw_if_interactive", None) | ||
| show = getattr(backend_mod, "show", None) |
There was a problem hiding this comment.
| draw_if_interactive = getattr(backend_mod, "draw_if_interactive", None) | |
| show = getattr(backend_mod, "show", None) | |
| # draw_if_interactive = getattr(backend_mod, "draw_if_interactive", None) | |
| # show = getattr(backend_mod, "show", None) |
These are not used yet so I would prefer to not define them yet.
Sorry, that is my fault.
I thought we were going for "A backend is a |
Followup to the introduction of FigureCanvas.new_manager: allow backend modules to not define new_figure_manager anymore, in which case we derive the needed function from FigureCanvas.new_manager. (In the future, I plan to do the same with draw_if_interactive and show, so that "a backend is just a module with a FigureCanvas class"; the advantage is that the FigureCanvas subclass provided by the module can inherit methods as needed from the parent class.) For backcompat, the old codepath is maintained (and has priority). To test this, manually alter backend_bases._Backend.export and remove the new_figure_manager entry from the exported functions, which deletes that global function from all of the builtin methods (actually, we'll need a deprecation cycle), and check that pyplot still works fine. Also tweak the testing machinery to restore the original backend even if the backend was not switched via a pytest marker.
No worries, we'll figure something out...
In practice you need to support the first form, so if what you actually have is just the class, you can just pass |
Followup to the introduction of FigureCanvas.new_manager (#22925): allow backend
modules to not define new_figure_manager anymore, in which case we
derive the needed function from FigureCanvas.new_manager. (In the
future, I plan to do the same with draw_if_interactive and show, so that
"a backend is just a module with a FigureCanvas class"; the advantage is
that the FigureCanvas subclass provided by the module can inherit
methods as needed from the parent class.)
For backcompat, the old codepath is maintained (and has priority).
To test this, manually alter backend_bases._Backend.export and remove
the new_figure_manager entry from the exported functions, which deletes
that global function from all of the builtin methods (actually, we'll
need a deprecation cycle), and check that pyplot still works fine. Also
tweak the testing machinery to restore the original backend even if the
backend was not switched via a pytest marker.
PR Summary
PR Checklist
Tests and Styling
pytestpasses).flake8-docstringsand runflake8 --docstring-convention=all).Documentation
doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).