Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bc07a8e

Browse filesBrowse files
tacaswellMeeseeksDev[bot]
authored andcommitted
Backport PR #13057: Simplify callable(self._contains) checks
1 parent bc7b7a6 commit bc07a8e
Copy full SHA for bc07a8e

File tree

Expand file treeCollapse file tree

9 files changed

+14
-12
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+14
-12
lines changed

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def contains(self, mouseevent):
386386
--------
387387
set_contains, get_contains
388388
"""
389-
if callable(self._contains):
389+
if self._contains is not None:
390390
return self._contains(self, mouseevent)
391391
_log.warning("%r needs 'contains' method", self.__class__.__name__)
392392
return False, {}
@@ -414,6 +414,8 @@ def contains(artist: Artist, event: MouseEvent) -> bool, dict
414414
implementation of the respective artist, but may provide
415415
additional information.
416416
"""
417+
if not callable(picker):
418+
raise TypeError("picker is not a callable")
417419
self._contains = picker
418420

419421
def get_contains(self):

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4222,7 +4222,7 @@ def get_children(self):
42224222

42234223
def contains(self, mouseevent):
42244224
# docstring inherited.
4225-
if callable(self._contains):
4225+
if self._contains is not None:
42264226
return self._contains(self, mouseevent)
42274227
return self.patch.contains(mouseevent)
42284228

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def contains(self, mouseevent):
243243
This function always returns false. It is more useful to test if the
244244
axis as a whole contains the mouse rather than the set of tick marks.
245245
"""
246-
if callable(self._contains):
246+
if self._contains is not None:
247247
return self._contains(self, mouseevent)
248248
return False, {}
249249

@@ -1846,7 +1846,7 @@ class XAxis(Axis):
18461846
def contains(self, mouseevent):
18471847
"""Test whether the mouse event occurred in the x axis.
18481848
"""
1849-
if callable(self._contains):
1849+
if self._contains is not None:
18501850
return self._contains(self, mouseevent)
18511851

18521852
x, y = mouseevent.x, mouseevent.y
@@ -2155,7 +2155,7 @@ def contains(self, mouseevent):
21552155
21562156
Returns *True* | *False*
21572157
"""
2158-
if callable(self._contains):
2158+
if self._contains is not None:
21592159
return self._contains(self, mouseevent)
21602160

21612161
x, y = mouseevent.x, mouseevent.y

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def contains(self, mouseevent):
353353
Returns ``bool, dict(ind=itemlist)``, where every item in itemlist
354354
contains the event.
355355
"""
356-
if callable(self._contains):
356+
if self._contains is not None:
357357
return self._contains(self, mouseevent)
358358

359359
if not self.get_visible():

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+2-2Lines 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.
@@ -1302,7 +1302,7 @@ def get_window_extent(self, renderer=None):
13021302

13031303
def contains(self, mouseevent):
13041304
"""Test whether the mouse event occurred within the image."""
1305-
if callable(self._contains):
1305+
if self._contains is not None:
13061306
return self._contains(self, mouseevent)
13071307

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

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def contains(self, mouseevent, radius=None):
128128
129129
Returns T/F, {}
130130
"""
131-
if callable(self._contains):
131+
if self._contains is not None:
132132
return self._contains(self, mouseevent)
133133
radius = self._process_radius(radius)
134134
inside = self.get_path().contains_point(

‎lib/matplotlib/table.py

Copy file name to clipboardExpand all lines: lib/matplotlib/table.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/text.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def contains(self, mouseevent):
194194
-------
195195
bool : bool
196196
"""
197-
if callable(self._contains):
197+
if self._contains is not None:
198198
return self._contains(self, mouseevent)
199199

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.