Skip to content

FIX: Ensuring both x and y attrs of LocationEvent are int #11530

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 7 commits into from
Jul 1, 2018

Conversation

TarasKuzyo
Copy link
Contributor

PR Summary

Fixes issue #11496. Both x and y attributes of matplotlib.backend_bases.LocationEvent are casted to int in the constructor.

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 v3.0 milestone Jun 28, 2018
tacaswell
tacaswell previously approved these changes Jun 28, 2018
Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Test failure is real (x and y are sometimes None; whether that should indeed ever happen is another question).

Anyone can dismiss this once fixed.

@tacaswell tacaswell dismissed their stale review June 29, 2018 00:01

Because I missed a bug. This is why we have CI!

@tacaswell tacaswell dismissed anntzer’s stale review June 29, 2018 15:58

Tests now pass, None case handled

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.

Please pass None though.

self.x = x # x position - pixels from left of canvas
self.y = y # y position - pixels from right of canvas
# x position - pixels from left of canvas
self.x = int(x) if x is not None else 0
Copy link
Member

Choose a reason for hiding this comment

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

We should probably leave the current behavior of x and y being allowed to be None. I am not sure why that is allowed, but we should not change it!

@TarasKuzyo
Copy link
Contributor Author

The only place, where None is explicitly passed to x and y attributes of LocationEvent is FigureCanvasBase.enter_notify_event:
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backend_bases.py#L1858
On the other hand in KeyEvent's constructor zeros are passed for x and y:
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backend_bases.py#L1562

@NelleV
Copy link
Member

NelleV commented Jun 29, 2018

Hi @TarasKuzyo
Thanks for the contribution! This looks great.
I think the only element missing is a test, which I know can be challenging sometimes with Matplotlib. Do you think you can try adding this? In this particular case, it should be fairly straight forward and I am happy to help you out if need be.

@TarasKuzyo
Copy link
Contributor Author

Hi @NelleV, should this test simulate button_press_event on Canvas or just creating MouseEvent and checking appropriate attributes?

@NelleV
Copy link
Member

NelleV commented Jun 29, 2018

@TarasKuzyo no, I would go for something simpler, that checks that in the object is created with a float, it is casted properly as an integer during the object initialization. It's more targeted and way easier to implement, but also a good way to check we don't accidentally remove this feature.

@NelleV NelleV merged commit 06fd413 into matplotlib:master Jul 1, 2018
@NelleV
Copy link
Member

NelleV commented Jul 1, 2018

Thanks @TarasKuzyo !

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.

4 participants