Skip to content

Widgets: Remove deprecations and make arguments keyword only #26853

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 1 commit into from
Sep 24, 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
1 change: 0 additions & 1 deletion ci/mypy-stubtest-allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ matplotlib.cm.register_cmap
matplotlib.cm.unregister_cmap
matplotlib.collections.PolyCollection.span_where
matplotlib.gridspec.GridSpecBase.get_grid_positions
matplotlib.widgets.MultiCursor.needclear

# 3.8 deprecations
matplotlib.cbook.get_sample_data
Expand Down
26 changes: 26 additions & 0 deletions doc/api/next_api_changes/removals/26853-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Most arguments to widgets have been made keyword-only
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Passing all but the very few first arguments positionally in the constructors
of Widgets is now keyword-only. In general, all optional arguments are keyword-only.

``RadioButtons.circles``
~~~~~~~~~~~~~~~~~~~~~~~~

... is removed. (``RadioButtons`` now draws itself using `~.Axes.scatter`.)

``CheckButtons.rectangles`` and ``CheckButtons.lines``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``CheckButtons.rectangles`` and ``CheckButtons.lines`` are removed.
(``CheckButtons`` now draws itself using `~.Axes.scatter`.)

Remove unused parameter *x* to ``TextBox.begin_typing``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This parameter was unused in the method, but was a required argument.

``MultiCursor.needclear``
~~~~~~~~~~~~~~~~~~~~~~~~~

... is removed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 0 additions & 59 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import matplotlib.colors as mcolors
import matplotlib.widgets as widgets
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.lines import Line2D
from matplotlib.testing.decorators import check_figures_equal, image_comparison
from matplotlib.testing.widgets import (click_and_drag, do_event, get_ax,
mock_event, noop)
Expand Down Expand Up @@ -1055,16 +1053,10 @@ def test_check_radio_buttons_image():

rax1 = fig.add_axes((0.05, 0.7, 0.2, 0.15))
rb1 = widgets.RadioButtons(rax1, ('Radio 1', 'Radio 2', 'Radio 3'))
with pytest.warns(DeprecationWarning,
match='The circles attribute was deprecated'):
rb1.circles # Trigger the old-style elliptic radiobuttons.

rax2 = fig.add_axes((0.05, 0.5, 0.2, 0.15))
cb1 = widgets.CheckButtons(rax2, ('Check 1', 'Check 2', 'Check 3'),
(False, True, True))
with pytest.warns(DeprecationWarning,
match='The rectangles attribute was deprecated'):
cb1.rectangles # Trigger old-style Rectangle check boxes

rax3 = fig.add_axes((0.05, 0.3, 0.2, 0.15))
rb3 = widgets.RadioButtons(
Expand Down Expand Up @@ -1164,57 +1156,6 @@ def test_check_button_props(fig_test, fig_ref):
cb.set_check_props({**check_props, 's': (24 / 2)**2})


@check_figures_equal(extensions=["png"])
def test_check_buttons_rectangles(fig_test, fig_ref):
# Test should be removed once .rectangles is removed
cb = widgets.CheckButtons(fig_test.subplots(), ["", ""],
[False, False])
with pytest.warns(DeprecationWarning,
match='The rectangles attribute was deprecated'):
cb.rectangles
ax = fig_ref.add_subplot(xticks=[], yticks=[])
ys = [2/3, 1/3]
dy = 1/3
w, h = dy / 2, dy / 2
rectangles = [
Rectangle(xy=(0.05, ys[i] - h / 2), width=w, height=h,
edgecolor="black",
facecolor="none",
transform=ax.transAxes
)
for i, y in enumerate(ys)
]
for rectangle in rectangles:
ax.add_patch(rectangle)


@check_figures_equal(extensions=["png"])
def test_check_buttons_lines(fig_test, fig_ref):
# Test should be removed once .lines is removed
cb = widgets.CheckButtons(fig_test.subplots(), ["", ""], [True, True])
with pytest.warns(DeprecationWarning,
match='The lines attribute was deprecated'):
cb.lines
for rectangle in cb._rectangles:
rectangle.set_visible(False)
ax = fig_ref.add_subplot(xticks=[], yticks=[])
ys = [2/3, 1/3]
dy = 1/3
w, h = dy / 2, dy / 2
lineparams = {'color': 'k', 'linewidth': 1.25,
'transform': ax.transAxes,
'solid_capstyle': 'butt'}
for i, y in enumerate(ys):
x, y = 0.05, y - h / 2
l1 = Line2D([x, x + w], [y + h, y], **lineparams)
l2 = Line2D([x, x + w], [y, y + h], **lineparams)

l1.set_visible(True)
l2.set_visible(True)
ax.add_line(l1)
ax.add_line(l2)


def test_slider_slidermin_slidermax_invalid():
fig, ax = plt.subplots()
# test min/max with floats
Expand Down
Loading