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

Skip to content

Commit 896dbb5

Browse files
committed
Deprecate Artist.{set,get}_contains.
I don't think it makes sense to allow overriding contains() checks per instance -- and if someone really need that, they can use a custom artist subclass or even just monkeypatch the contains method; if they need it for pick events there's still Artist.set_picker which is not going away. This came in in 8111a3a (2007) and was apparently never used or tested.
1 parent 2c5c351 commit 896dbb5

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,13 @@ Setting a `.Line2D`\'s pickradius (i.e. the tolerance for pick events
142142
and containment checks) via `.Line2D.set_picker` is deprecated. Use
143143
`.Line2D.set_pickradius` instead.
144144

145-
`.Line2D.set_picker` no longer sets the artist's custom-contain() check. Use
146-
``Line2D.set_contains`` instead.
145+
`.Line2D.set_picker` no longer sets the artist's custom-contain() check.
146+
147+
``Artist.set_contains``, ``Artist.get_contains``
148+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149+
Setting a custom method overridding `.Artist.contains` is deprecated.
150+
There is no replacement, but you may still customize pick events using
151+
`.Artist.set_picker`.
147152

148153
`~matplotlib.colorbar.Colorbar` methods
149154
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/matplotlib/artist.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,13 @@ def _default_contains(self, mouseevent, figure=None):
396396
The `canvas` kwarg is provided for the implementation of
397397
`Figure.contains`.
398398
"""
399-
if callable(self._contains):
400-
return self._contains(self, mouseevent)
401399
if figure is not None and mouseevent.canvas is not figure.canvas:
402400
return False, {}
403401
return None, {}
404402

405403
def contains(self, mouseevent):
406-
"""Test whether the artist contains the mouse event.
404+
"""
405+
Test whether the artist contains the mouse event.
407406
408407
Parameters
409408
----------
@@ -417,17 +416,14 @@ def contains(self, mouseevent):
417416
An artist-specific dictionary of details of the event context,
418417
such as which points are contained in the pick radius. See the
419418
individual Artist subclasses for details.
420-
421-
See Also
422-
--------
423-
set_contains, get_contains
424419
"""
425420
inside, info = self._default_contains(mouseevent)
426421
if inside is not None:
427422
return inside, info
428423
_log.warning("%r needs 'contains' method", self.__class__.__name__)
429424
return False, {}
430425

426+
@cbook.deprecated("3.3", alternative="set_picker")
431427
def set_contains(self, picker):
432428
"""
433429
Define a custom contains test for the artist.
@@ -455,6 +451,7 @@ def contains(artist: Artist, event: MouseEvent) -> bool, dict
455451
raise TypeError("picker is not a callable")
456452
self._contains = picker
457453

454+
@cbook.deprecated("3.3", alternative="get_picker")
458455
def get_contains(self):
459456
"""
460457
Return the custom contains function of the artist if set, or *None*.

0 commit comments

Comments
 (0)