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

Skip to content

Commit 06081dc

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 self._contains is not None.
1 parent b9c2b26 commit 06081dc

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
@@ -383,7 +383,7 @@ def contains(self, mouseevent):
383383
--------
384384
set_contains, get_contains
385385
"""
386-
if callable(self._contains):
386+
if self._contains is not None:
387387
return self._contains(self, mouseevent)
388388
_log.warning("%r needs 'contains' method", self.__class__.__name__)
389389
return False, {}
@@ -411,6 +411,8 @@ def contains(artist: Artist, event: MouseEvent) -> bool, dict
411411
implementation of the respective artist, but may provide
412412
additional information.
413413
"""
414+
if not callable(picker):
415+
raise TypeError("picker is not a callable")
414416
self._contains = picker
415417

416418
def get_contains(self):

lib/matplotlib/axes/_base.py

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

42304230
def contains(self, mouseevent):
42314231
# docstring inherited.
4232-
if callable(self._contains):
4232+
if self._contains is not None:
42334233
return self._contains(self, mouseevent)
42344234
return self.patch.contains(mouseevent)
42354235

lib/matplotlib/axis.py

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

@@ -1858,7 +1858,7 @@ class XAxis(Axis):
18581858
def contains(self, mouseevent):
18591859
"""Test whether the mouse event occurred in the x axis.
18601860
"""
1861-
if callable(self._contains):
1861+
if self._contains is not None:
18621862
return self._contains(self, mouseevent)
18631863

18641864
x, y = mouseevent.x, mouseevent.y
@@ -2202,7 +2202,7 @@ def contains(self, mouseevent):
22022202
22032203
Returns *True* | *False*
22042204
"""
2205-
if callable(self._contains):
2205+
if self._contains is not None:
22062206
return self._contains(self, mouseevent)
22072207

22082208
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 is not None:
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
@@ -656,7 +656,7 @@ def contains(self, mouseevent):
656656
-------
657657
bool, {}
658658
"""
659-
if callable(self._contains):
659+
if self._contains is not None:
660660
return self._contains(self, mouseevent)
661661
inside = self.bbox.contains(mouseevent.x, mouseevent.y)
662662
return inside, {}

lib/matplotlib/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def contains(self, mouseevent):
613613
"""
614614
Test whether the mouse event occurred within the image.
615615
"""
616-
if callable(self._contains):
616+
if self._contains is not None:
617617
return self._contains(self, mouseevent)
618618
# TODO: make sure this is consistent with patch and patch
619619
# collection on nonlinear transformed coordinates.
@@ -1310,7 +1310,7 @@ def get_window_extent(self, renderer=None):
13101310

13111311
def contains(self, mouseevent):
13121312
"""Test whether the mouse event occurred within the image."""
1313-
if callable(self._contains):
1313+
if self._contains is not None:
13141314
return self._contains(self, mouseevent)
13151315

13161316
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 is not None:
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 is not None:
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 is not None:
197197
return self._contains(self, mouseevent)
198198

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

0 commit comments

Comments
 (0)