Skip to content

Commit 0886e70

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 db8cdf2 commit 0886e70

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

doc/api/next_api_changes/deprecations.rst

+7-2
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

+7-8
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def _default_contains(self, mouseevent, figure=None):
380380
"""
381381
Base impl. for checking whether a mouseevent happened in an artist.
382382
383-
1. If the artist defines a custom checker, use it.
383+
1. If the artist defines a custom checker, use it (deprecated).
384384
2. If the artist figure is known and the event did not occur in that
385385
figure (by checking its ``canvas`` attribute), reject it.
386386
3. Otherwise, return `None, {}`, indicating that the subclass'
@@ -393,17 +393,18 @@ def _default_contains(self, mouseevent, figure=None):
393393
return inside, info
394394
# subclass-specific implementation follows
395395
396-
The `canvas` kwarg is provided for the implementation of
396+
The *figure* kwarg is provided for the implementation of
397397
`Figure.contains`.
398398
"""
399399
if callable(self._contains):
400-
return self._contains(self, mouseevent)
400+
return self._contains(self, mouseevent)
401401
if figure is not None and mouseevent.canvas is not figure.canvas:
402402
return False, {}
403403
return None, {}
404404

405405
def contains(self, mouseevent):
406-
"""Test whether the artist contains the mouse event.
406+
"""
407+
Test whether the artist contains the mouse event.
407408
408409
Parameters
409410
----------
@@ -417,17 +418,14 @@ def contains(self, mouseevent):
417418
An artist-specific dictionary of details of the event context,
418419
such as which points are contained in the pick radius. See the
419420
individual Artist subclasses for details.
420-
421-
See Also
422-
--------
423-
set_contains, get_contains
424421
"""
425422
inside, info = self._default_contains(mouseevent)
426423
if inside is not None:
427424
return inside, info
428425
_log.warning("%r needs 'contains' method", self.__class__.__name__)
429426
return False, {}
430427

428+
@cbook.deprecated("3.3", alternative="set_picker")
431429
def set_contains(self, picker):
432430
"""
433431
Define a custom contains test for the artist.
@@ -455,6 +453,7 @@ def contains(artist: Artist, event: MouseEvent) -> bool, dict
455453
raise TypeError("picker is not a callable")
456454
self._contains = picker
457455

456+
@cbook.deprecated("3.3", alternative="get_picker")
458457
def get_contains(self):
459458
"""
460459
Return the custom contains function of the artist if set, or *None*.

0 commit comments

Comments
 (0)