Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Fix" tight_layout for template backend. #17731

Merged
merged 2 commits into from Jun 24, 2020
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 23, 2020

We rely on print_foo actually walking through the Figure tree (which any
non-trivial canvas should likely do...).

Closes #17730.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added this to the v3.3.0 milestone Jun 23, 2020
Copy link
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.

Is it possible to add a test to make sure this won‘t break later?

Can you add a comment/docs to make template implementors aware of this?

@anntzer
Copy link
Contributor Author

anntzer commented Jun 23, 2020

To be honest I don't know why we expose the template backend as a "real" backend, but heh.
I wouldn't bother with docs unless someone shows me a real backend that can implement print_foo() without walking the Figure tree...

@tacaswell
Copy link
Member

How is this preventing a unbound local?

@anntzer
Copy link
Contributor Author

anntzer commented Jun 23, 2020

The unbound local comes from the fact that previously, FigureCanvasTemplate.print_foo() did not figure.draw(renderer) (which I argue is unrealistic of any non-trivial drawer), whereas get_renderer() works by overriding figure.draw() to immediately throw ("goto") back to the caller and propagating the renderer out of the call stack. Now print_foo() does call figure.draw(renderer) and everyone is happy.

@jni
Copy link
Contributor

jni commented Jun 24, 2020

With the caveat that I don't know the codebase, it seems to me that UnboundLocals need to be fixed in the code structure itself and should not be allowed to happen, regardless of what a canvas should do vs actually does.

I also agree with @timhoffm that a test should be added, especially since based on comments in #17730 skimage might move to Agg for this check, which means we wouldn't be implicitly testing this for you in the future. 😬

We rely on print_foo actually walking through the Figure tree (which any
non-trivial canvas should likely do...).
@anntzer
Copy link
Contributor Author

anntzer commented Jun 24, 2020

Got rid of the UnboundLocalError (in favor of a RuntimeError). Someone else gets to write the test if you really want it... (I'd think we should just run a full test suite against all of backend_template (which is completely untested) if we really want to support that, rather than doing so in a piecemeal fashion).

@anntzer
Copy link
Contributor Author

anntzer commented Jun 24, 2020

Pushed a second commit that fixes #17744. May be better to rewrite _get_output_canvas() to be a context-manager that auto-restores the original canvas at exit, but let's keep that for later (also, name suggestions would be welcome).

@QuLogic QuLogic merged commit 0cf3974 into matplotlib:master Jun 24, 2020
@QuLogic
Copy link
Member

QuLogic commented Jun 24, 2020

Oh, I forgot about the testing stuff, oh well.

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jun 24, 2020
@anntzer anntzer deleted the template branch June 24, 2020 21:42
tacaswell added a commit that referenced this pull request Jun 24, 2020
…731-on-v3.3.x

Backport PR #17731 on branch v3.3.x ("Fix" tight_layout for template backend.)
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.

Using backend Template and plt.tight_layout raises UnboundLocalError
5 participants