Deduplicate implementation of per-backend Tools. by anntzer · Pull Request #12760 · matplotlib/matplotlib · GitHub
Skip to content

Deduplicate implementation of per-backend Tools. - #12760

Merged
tacaswell merged 1 commit into
matplotlib:masterfrom
anntzer:deduplicate-tools
Mar 18, 2019
Merged

tacaswell merged 1 commit into
matplotlib:masterfrom
anntzer:deduplicate-tools

Conversation

@anntzer

@anntzer anntzer commented Nov 6, 2018

Copy link
Copy Markdown
Contributor

... by reusing the old Toolbar-based implementations.

If toolmanager ever becomes the default we can move the implementations
there and conversely point the old Toolbar-based implementations to use
the Tools.

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.1 milestone Nov 6, 2018
Comment thread lib/matplotlib/backends/_backend_tk.py Outdated

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.

Suggested change
# Avoid using this (prefer self.canvas.manager.window), so that Tool
# Avoid using self.window (prefer self.canvas.manager.window), so that Tool

Does it make sense to make this a property or are there use-cases where window != self.canvas.manager.window?

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.

Actually I think this attribute should be deprecated (because it is not consistent across backend implementations, so any cross-backend code will need to use self.canvas.manager.window anyways, and that doesn't seem to be so hard to type that you'd also want a property for it (if anything, making the NavigationToolbar APIs consistent across toolkits should be the object of another PR)).

But that's orthogonal to the PR, because the point of the comment is that sometimes, NavigationToolbar methods get called without a true NavigationToolbar as first argument, but a proxy created with _make_classic_style_pseudo_toolbar(), and these won't have a window attribute.


class RubberbandTk(backend_tools.RubberbandBase):
def __init__(self, *args, **kwargs):
backend_tools.RubberbandBase.__init__(self, *args, **kwargs)

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.

It seems that RubberbandBase does not have an __init__. So technically, this change is possible.

Generally, is it wise not to call super().__init__(). The parent class may later add an __init__() method.

Here in particular, while RubberbandBase does not have __init__(), its parent ToolBase has, which does not get called also with the existing code. That doesn't look right to me.

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.

It will get called even after deleting this code block: when instantiating a RubberbandTk, Python will call RubberbandTk.__init__; because RubberbandTk does not define an __init__, it is inherited by looking up in the base classes; ultimately this resolves to ToolBase.init`.
In other words, the deleted code block does not do anything.

@timhoffm timhoffm left a comment

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 think something should be done about self.window, because having an attribute that should not be used or at least not be used in certain situations is not reasonable. However, changing/deprecating window is beyond the scope of this PR.

With respect to keeping PRs small, I accept the introduced limitation on self.window within this PR. Ideally, we would first have a PR that cares for self.window and merge this PR only after that.

@anntzer

anntzer commented Dec 16, 2018

Copy link
Copy Markdown
Contributor Author

... by reusing the old Toolbar-based implementations.

If toolmanager ever becomes the default we can move the implementations
there and conversely point the old Toolbar-based implementations to use
the Tools.
@tacaswell
tacaswell merged commit 24524c4 into matplotlib:master Mar 18, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Mar 18, 2019
@anntzer
anntzer deleted the deduplicate-tools branch March 18, 2019 20:02
timhoffm added a commit that referenced this pull request Mar 18, 2019
…760-on-v3.1.x

Backport PR #12760 on branch v3.1.x (Deduplicate implementation of per-backend Tools.)
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.

3 participants