Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cooperative __init__ for Qt4 canvas. #9052

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

Merged
merged 1 commit into from
Aug 22, 2017

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Aug 17, 2017

Alternate for #9048 (basically pulling out the relevant parts of #8771, but using a local monkey-patch approach.
I personally find this approach clearer in intent ("PyQt4 does not support multiple inheritance so let's just locally patch it so that it does") than #9048.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 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

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Aug 17, 2017
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Aug 17, 2017
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

One paranoid comment, but overall seems reasonable.


@functools.wraps(__init__)
def wrapper(self, **kwargs):
QtWidgets.QWidget.__init__ = cooperative_qwidget_init
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be in a try..finally block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

The initial monkey-patch should also be in the try block... ctrl-c can happen anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow, I'm a bit ashamed I never thought about this point :-)

@tacaswell
Copy link
Member

I lean towards this as the better solution (I started writing a comment about how I was even between them and in the process convinced my self to prefer this one).

This has the advantage of being cleaner and more localized but hard-codes the non-cooperative modules in. However, odds of another binding showing up are low and doing the sub-classing and replacing __init__ while waiting for changes to be merged upstream isn't that bad.

#9048 uses 'simpler' python, but it makes the class zoo one class bigger and has to use two differently named 'magic' cut-out function, and is spread across a couple of files. It makes the unlikely extension case easier (once you understand the code), but harder to understand to begin with.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

Be more paranoid in re-setting the __init__

@anntzer anntzer force-pushed the cooperative-pyqt4-init branch from 5ee6e51 to 7b09c20 Compare August 17, 2017 23:37
@anntzer
Copy link
Contributor Author

anntzer commented Aug 17, 2017

try... finally added.
Honestly, I think anyone coming up with a new qt binding that does not support cooperative inheritance does not deserve being supported by matplotlib :-) (you can make the mistake once, but you should learn from previous mistakes!)

@anntzer anntzer force-pushed the cooperative-pyqt4-init branch from 7b09c20 to f007419 Compare August 18, 2017 06:46
@efiring
Copy link
Member

efiring commented Aug 21, 2017

Appveyor failure is just a hang at the start of the conda-build on 3.6.

@tacaswell tacaswell merged commit c0bceb1 into matplotlib:master Aug 22, 2017
@anntzer anntzer deleted the cooperative-pyqt4-init branch August 22, 2017 16:18
@anntzer anntzer mentioned this pull request Aug 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI: Qt Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants