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

Skip to content

Commit cfb6c29

Browse files
committed
Simplify callable(self._contains) checks
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).
1 parent 529eb3d commit cfb6c29

File tree

9 files changed

+14
-12
lines changed

9 files changed

+14
-12
lines changed

lib/matplotlib/artist.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def contains(self, mouseevent):
402402
--------
403403
set_contains, get_contains
404404
"""
405-
if callable(self._contains):
405+
if self._contains:
406406
return self._contains(self, mouseevent)
407407
_log.warning("%r needs 'contains' method", self.__class__.__name__)
408408
return False, {}
@@ -430,6 +430,8 @@ def contains(artist: Artist, event: MouseEvent) -> bool, dict
430430
implementation of the respective artist, but may provide
431431
additional information.
432432
"""
433+
if not callable(picker):
434+
raise TypeError("picker is not a callable")
433435
self._contains = picker
434436

435437
def get_contains(self):

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4257,7 +4257,7 @@ def get_children(self):
42574257

42584258
def contains(self, mouseevent):
42594259
# docstring inherited.
4260-
if callable(self._contains):
4260+
if self._contains:
42614261
return self._contains(self, mouseevent)
42624262
return self.patch.contains(mouseevent)
42634263

lib/matplotlib/axis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def contains(self, mouseevent):
244244
This function always returns false. It is more useful to test if the
245245
axis as a whole contains the mouse rather than the set of tick marks.
246246
"""
247-
if callable(self._contains):
247+
if self._contains:
248248
return self._contains(self, mouseevent)
249249
return False, {}
250250

@@ -1781,7 +1781,7 @@ class XAxis(Axis):
17811781
def contains(self, mouseevent):
17821782
"""Test whether the mouse event occurred in the x axis.
17831783
"""
1784-
if callable(self._contains):
1784+
if self._contains:
17851785
return self._contains(self, mouseevent)
17861786

17871787
x, y = mouseevent.x, mouseevent.y
@@ -2152,7 +2152,7 @@ def contains(self, mouseevent):
21522152
21532153
Returns *True* | *False*
21542154
"""
2155-
if callable(self._contains):
2155+
if self._contains:
21562156
return self._contains(self, mouseevent)
21572157

21582158
x, y = mouseevent.x, mouseevent.y

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def contains(self, mouseevent):
352352
Returns ``bool, dict(ind=itemlist)``, where every item in itemlist
353353
contains the event.
354354
"""
355-
if callable(self._contains):
355+
if self._contains:
356356
return self._contains(self, mouseevent)
357357

358358
if not self.get_visible():

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ def contains(self, mouseevent):
658658
-------
659659
bool, {}
660660
"""
661-
if callable(self._contains):
661+
if self._contains:
662662
return self._contains(self, mouseevent)
663663
inside = self.bbox.contains(mouseevent.x, mouseevent.y)
664664
return inside, {}

lib/matplotlib/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def contains(self, mouseevent):
591591
"""
592592
Test whether the mouse event occurred within the image.
593593
"""
594-
if callable(self._contains):
594+
if self._contains:
595595
return self._contains(self, mouseevent)
596596
# TODO: make sure this is consistent with patch and patch
597597
# collection on nonlinear transformed coordinates.
@@ -1291,7 +1291,7 @@ def get_window_extent(self, renderer=None):
12911291

12921292
def contains(self, mouseevent):
12931293
"""Test whether the mouse event occurred within the image."""
1294-
if callable(self._contains):
1294+
if self._contains:
12951295
return self._contains(self, mouseevent)
12961296

12971297
if not self.get_visible(): # or self.get_figure()._renderer is None:

lib/matplotlib/patches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def contains(self, mouseevent, radius=None):
127127
128128
Returns T/F, {}
129129
"""
130-
if callable(self._contains):
130+
if self._contains:
131131
return self._contains(self, mouseevent)
132132
radius = self._process_radius(radius)
133133
inside = self.get_path().contains_point(

lib/matplotlib/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def _get_grid_bbox(self, renderer):
438438

439439
def contains(self, mouseevent):
440440
# docstring inherited
441-
if callable(self._contains):
441+
if self._contains:
442442
return self._contains(self, mouseevent)
443443

444444
# TODO: Return index of the cell containing the cursor so that the user

lib/matplotlib/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def contains(self, mouseevent):
193193
-------
194194
bool : bool
195195
"""
196-
if callable(self._contains):
196+
if self._contains:
197197
return self._contains(self, mouseevent)
198198

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

0 commit comments

Comments
 (0)