Skip to content

Backport PR #24254 on branch v3.7.x (Expire deprecations in widgets and keyword only arguments for Selectors) #24959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/deprecations/24254-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Most arguments to widgets have been made keyword-only
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Passing all but the very few first arguments positionally in the constructors
of Widgets is deprecated. Most arguments will become keyword-only in a future
version.
64 changes: 64 additions & 0 deletions doc/api/next_api_changes/removals/24254-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Removal of deprecations in the Selector widget API
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

RectangleSelector and EllipseSelector
.....................................

The *drawtype* keyword argument to `~matplotlib.widgets.RectangleSelector` is
removed. From now on, the only behaviour will be ``drawtype='box'``.

Support for ``drawtype=line`` is removed altogether. As a
result, the *lineprops* keyword argument to
`~matplotlib.widgets.RectangleSelector` is also removed.

To retain the behaviour of ``drawtype='none'``, use ``rectprops={'visible':
False}`` to make the drawn `~matplotlib.patches.Rectangle` invisible.

Cleaned up attributes and arguments are:

- The ``active_handle`` attribute has been privatized and removed.
- The ``drawtype`` attribute has been privatized and removed.
- The ``eventpress`` attribute has been privatized and removed.
- The ``eventrelease`` attribute has been privatized and removed.
- The ``interactive`` attribute has been privatized and removed.
- The *marker_props* argument is removed, use *handle_props* instead.
- The *maxdist* argument is removed, use *grab_range* instead.
- The *rectprops* argument is removed, use *props* instead.
- The ``rectprops`` attribute has been privatized and removed.
- The ``state`` attribute has been privatized and removed.
- The ``to_draw`` attribute has been privatized and removed.

PolygonSelector
...............

- The *line* attribute is removed. If you want to change the selector artist
properties, use the ``set_props`` or ``set_handle_props`` methods.
- The *lineprops* argument is removed, use *props* instead.
- The *markerprops* argument is removed, use *handle_props* instead.
- The *maxdist* argument and attribute is removed, use *grab_range* instead.
- The *vertex_select_radius* argument and attribute is removed, use
*grab_range* instead.

SpanSelector
............

- The ``active_handle`` attribute has been privatized and removed.
- The ``eventpress`` attribute has been privatized and removed.
- The ``eventrelease`` attribute has been privatized and removed.
- The ``pressv`` attribute has been privatized and removed.
- The ``prev`` attribute has been privatized and removed.
- The ``rect`` attribute has been privatized and removed.
- The *rectprops* parameter has been renamed to *props*.
- The ``rectprops`` attribute has been privatized and removed.
- The *span_stays* parameter has been renamed to *interactive*.
- The ``span_stays`` attribute has been privatized and removed.
- The ``state`` attribute has been privatized and removed.

LassoSelector
.............

- The *lineprops* argument is removed, use *props* instead.
- The ``onpress`` and ``onrelease`` methods are removed. They are straight
aliases for ``press`` and ``release``.
- The ``matplotlib.widgets.TextBox.DIST_FROM_LEFT`` attribute has been
removed. It was marked as private in 3.5.
21 changes: 7 additions & 14 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from contextlib import nullcontext
import functools
from unittest import mock

Expand All @@ -24,22 +23,16 @@ def ax():
return get_ax()


@pytest.mark.parametrize('kwargs, warning_msg', [
(dict(), None),
(dict(drawtype='line', useblit=False),
"Support for drawtype='line' is deprecated"),
(dict(useblit=True, button=1), None),
(dict(drawtype='none', minspanx=10, minspany=10),
"Support for drawtype='none' is deprecated"),
(dict(minspanx=10, minspany=10, spancoords='pixels'), None),
(dict(props=dict(fill=True)), None),
@pytest.mark.parametrize('kwargs', [
dict(),
dict(useblit=True, button=1),
dict(minspanx=10, minspany=10, spancoords='pixels'),
dict(props=dict(fill=True)),
])
def test_rectangle_selector(ax, kwargs, warning_msg):
def test_rectangle_selector(ax, kwargs):
onselect = mock.Mock(spec=noop, return_value=None)

with (pytest.warns(MatplotlibDeprecationWarning, match=warning_msg)
if warning_msg else nullcontext()):
tool = widgets.RectangleSelector(ax, onselect, **kwargs)
tool = widgets.RectangleSelector(ax, onselect, **kwargs)
do_event(tool, 'press', xdata=100, ydata=100, button=1)
do_event(tool, 'onmove', xdata=199, ydata=199, button=1)

Expand Down
Loading