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

Skip to content

Simplify callable(self._contains) checks #13057

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
Feb 23, 2019

Conversation

twmr
Copy link
Contributor

@twmr twmr commented Dec 27, 2018

Artist._contains can either be None (not-set) or a callable (see
docstring of Artist.set_contains). Therefore, the
callable(self._contains) checks can be simplified to
bool(self._contains).

PR Summary

I had a look at the traitlets PR (#4762, still has unresolved merge conflicts) and noticed some parts that could be moved to its own PR.

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

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.

Not quite sure if the change is worth the effort. But if so, it should be an explicit ˋis not Noneˋ check.

@@ -430,6 +430,8 @@ def contains(artist: Artist, event: MouseEvent) -> bool, dict
implementation of the respective artist, but may provide
additional information.
"""
if not callable(picker):
Copy link
Member

Choose a reason for hiding this comment

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

I think it‘s reasonable to keep this check. And not just fail when trying to call _contains

@twmr
Copy link
Contributor Author

twmr commented Dec 28, 2018

I'm also not really sure if it is worth the effort. @rmorshea do you remember why you had to change the _contains checks in #4762?

@timhoffm is it documented somewhere that the explicit if x is not None checks are preferred over the if x checks in matplotlib? I'm aware of the differences but I don't understand why matplotlib prefers the explicit if x is not None checks.

@timhoffm
Copy link
Member

None-check handling is not documented within matplotlib. However, it's general PEP8.

@twmr twmr force-pushed the simplifycallable branch from cfb6c29 to ac470d9 Compare February 2, 2019 19:02
Artist._contains can either be None (not-set) or a callable (see
docstring of Artist.set_contains). Therefore, the
callable(self._contains) checks can be simplified to
self._contains is not None.
@twmr twmr force-pushed the simplifycallable branch from ac470d9 to 06081dc Compare February 2, 2019 19:04
@twmr
Copy link
Contributor Author

twmr commented Feb 2, 2019

None-check handling is not documented within matplotlib. However, it's general PEP8.

Thx.

I've added "is not None" to all self._contains checks.

@timhoffm timhoffm added this to the v3.1.0 milestone Feb 14, 2019
@timhoffm
Copy link
Member

This is a small change, bit still to good. self._contains is not None is more what we actually want to check semantically than callable(self._contains).

@tacaswell tacaswell merged commit fdfe898 into matplotlib:master Feb 23, 2019
@tacaswell
Copy link
Member

Thanks @Thisch !

@lumberbot-app
Copy link

lumberbot-app bot commented Feb 23, 2019

Something went wrong ... Please have a look at my logs.

tacaswell added a commit that referenced this pull request Feb 23, 2019
…057-on-v3.1.x

Backport PR #13057 on branch v3.1.x (Simplify callable(self._contains) checks)
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