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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def contains(self, mouseevent):
--------
set_contains, get_contains
"""
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)
_log.warning("%r needs 'contains' method", self.__class__.__name__)
return False, {}
Expand Down Expand Up @@ -411,6 +411,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

raise TypeError("picker is not a callable")
self._contains = picker

def get_contains(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4229,7 +4229,7 @@ def get_children(self):

def contains(self, mouseevent):
# docstring inherited.
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)
return self.patch.contains(mouseevent)

Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def contains(self, mouseevent):
This function always returns false. It is more useful to test if the
axis as a whole contains the mouse rather than the set of tick marks.
"""
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)
return False, {}

Expand Down Expand Up @@ -1858,7 +1858,7 @@ class XAxis(Axis):
def contains(self, mouseevent):
"""Test whether the mouse event occurred in the x axis.
"""
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)

x, y = mouseevent.x, mouseevent.y
Expand Down Expand Up @@ -2202,7 +2202,7 @@ def contains(self, mouseevent):

Returns *True* | *False*
"""
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)

x, y = mouseevent.x, mouseevent.y
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def contains(self, mouseevent):
Returns ``bool, dict(ind=itemlist)``, where every item in itemlist
contains the event.
"""
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)

if not self.get_visible():
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def contains(self, mouseevent):
-------
bool, {}
"""
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)
inside = self.bbox.contains(mouseevent.x, mouseevent.y)
return inside, {}
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def contains(self, mouseevent):
"""
Test whether the mouse event occurred within the image.
"""
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)
# TODO: make sure this is consistent with patch and patch
# collection on nonlinear transformed coordinates.
Expand Down Expand Up @@ -1310,7 +1310,7 @@ def get_window_extent(self, renderer=None):

def contains(self, mouseevent):
"""Test whether the mouse event occurred within the image."""
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)

if not self.get_visible(): # or self.get_figure()._renderer is None:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def contains(self, mouseevent, radius=None):

Returns T/F, {}
"""
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)
radius = self._process_radius(radius)
inside = self.get_path().contains_point(
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def _get_grid_bbox(self, renderer):

def contains(self, mouseevent):
# docstring inherited
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)

# TODO: Return index of the cell containing the cursor so that the user
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def contains(self, mouseevent):
-------
bool : bool
"""
if callable(self._contains):
if self._contains is not None:
return self._contains(self, mouseevent)

if not self.get_visible() or self._renderer is None:
Expand Down