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

Skip to content

Expire deprecations in widgets and keyword only arguments for Selectors #24254

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
merged 4 commits into from
Jan 12, 2023
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``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removal of TextBox.DIST_FROM_LEFT is missing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW this is all just copied and pasted from the 3.5 release notes and deprecated replaced with removed (more or less).

But I will of course edit accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was deprecated in bd9ee5e but we did not get a API change note with it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I update this to be deprecated in 3.7?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been warning, but was not documented. The conservative thing to do is put it back, document it removed in 3.7 and drop it in 3.8, but I'm inclined to be a bit YOLO here and just document that it is removed in 3.7 as this is a very niche feature...

- 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