Skip to content

Commit 739aeb9

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 32d3306 commit 739aeb9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-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: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def _default_contains(self, mouseevent, figure=None):
383383
"""
384384
Base impl. for checking whether a mouseevent happened in an artist.
385385
386-
1. If the artist defines a custom checker, use it.
386+
1. If the artist defines a custom checker, use it (deprecated).
387387
2. If the artist figure is known and the event did not occur in that
388388
figure (by checking its ``canvas`` attribute), reject it.
389389
3. Otherwise, return `None, {}`, indicating that the subclass'
@@ -396,7 +396,7 @@ def _default_contains(self, mouseevent, figure=None):
396396
return inside, info
397397
# subclass-specific implementation follows
398398
399-
The `canvas` kwarg is provided for the implementation of
399+
The *figure* kwarg is provided for the implementation of
400400
`Figure.contains`.
401401
"""
402402
if callable(self._contains):
@@ -406,7 +406,8 @@ def _default_contains(self, mouseevent, figure=None):
406406
return None, {}
407407

408408
def contains(self, mouseevent):
409-
"""Test whether the artist contains the mouse event.
409+
"""
410+
Test whether the artist contains the mouse event.
410411
411412
Parameters
412413
----------
@@ -420,17 +421,14 @@ def contains(self, mouseevent):
420421
An artist-specific dictionary of details of the event context,
421422
such as which points are contained in the pick radius. See the
422423
individual Artist subclasses for details.
423-
424-
See Also
425-
--------
426-
set_contains, get_contains
427424
"""
428425
inside, info = self._default_contains(mouseevent)
429426
if inside is not None:
430427
return inside, info
431428
_log.warning("%r needs 'contains' method", self.__class__.__name__)
432429
return False, {}
433430

431+
@cbook.deprecated("3.3", alternative="set_picker")
434432
def set_contains(self, picker):
435433
"""
436434
Define a custom contains test for the artist.
@@ -458,6 +456,7 @@ def contains(artist: Artist, event: MouseEvent) -> bool, dict
458456
raise TypeError("picker is not a callable")
459457
self._contains = picker
460458

459+
@cbook.deprecated("3.3", alternative="get_picker")
461460
def get_contains(self):
462461
"""
463462
Return the custom contains function of the artist if set, or *None*.

0 commit comments

Comments
 (0)