From 25331147b1017fd5e0b70a16f99029bfb0a0c46c Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 17 Dec 2020 01:28:01 +0100 Subject: [PATCH 1/3] Move internal usage from cbook._rename_parameter to _api.rename_parameter --- lib/matplotlib/_api/__init__.py | 2 +- lib/matplotlib/_api/deprecation.py | 8 ++++---- lib/matplotlib/_mathtext.py | 2 +- lib/matplotlib/axes/_axes.py | 2 +- lib/matplotlib/cbook/__init__.py | 2 +- lib/matplotlib/pyplot.py | 10 +++++----- lib/matplotlib/scale.py | 22 ++++++++++----------- lib/matplotlib/tests/test_pyplot.py | 4 ++-- lib/mpl_toolkits/axisartist/angle_helper.py | 4 ++-- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/matplotlib/_api/__init__.py b/lib/matplotlib/_api/__init__.py index fba2d2e7e1dc..b366e7a3afba 100644 --- a/lib/matplotlib/_api/__init__.py +++ b/lib/matplotlib/_api/__init__.py @@ -17,7 +17,7 @@ from .deprecation import ( deprecated, warn_deprecated, - _rename_parameter, _delete_parameter, _make_keyword_only, + rename_parameter, _delete_parameter, _make_keyword_only, _deprecate_method_override, _deprecate_privatize_attribute, suppress_matplotlib_deprecation_warning, MatplotlibDeprecationWarning) diff --git a/lib/matplotlib/_api/deprecation.py b/lib/matplotlib/_api/deprecation.py index 13d2b3caface..63aee8592b35 100644 --- a/lib/matplotlib/_api/deprecation.py +++ b/lib/matplotlib/_api/deprecation.py @@ -294,7 +294,7 @@ def __set_name__(self, owner, name): property(lambda self: getattr(self, f"_{name}")), name=name)) -def _rename_parameter(since, old, new, func=None): +def rename_parameter(since, old, new, func=None): """ Decorator indicating that parameter *old* of *func* is renamed to *new*. @@ -309,12 +309,12 @@ def _rename_parameter(since, old, new, func=None): -------- :: - @_rename_parameter("3.1", "bad_name", "good_name") + @_api.rename_parameter("3.1", "bad_name", "good_name") def func(good_name): ... """ if func is None: - return functools.partial(_rename_parameter, since, old, new) + return functools.partial(rename_parameter, since, old, new) signature = inspect.signature(func) assert old not in signature.parameters, ( @@ -459,7 +459,7 @@ def _make_keyword_only(since, name, func=None): @functools.wraps(func) def wrapper(*args, **kwargs): # Don't use signature.bind here, as it would fail when stacked with - # _rename_parameter and an "old" argument name is passed in + # rename_parameter and an "old" argument name is passed in # (signature.bind would fail, but the actual call would succeed). idx = [*func.__signature__.parameters].index(name) if len(args) > idx: diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index dd0305d4b20a..a3de051240f6 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -158,7 +158,7 @@ def set_canvas_size(self, w, h, d): self.mathtext_backend.set_canvas_size( self.width, self.height, self.depth) - @cbook._rename_parameter("3.4", "facename", "font") + @_api.rename_parameter("3.4", "facename", "font") def render_glyph(self, ox, oy, font, font_class, sym, fontsize, dpi): """ At position (*ox*, *oy*), draw the glyph specified by the remaining diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 0ce6ac03b3fc..11a157a7f80f 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -645,7 +645,7 @@ def text(self, x, y, s, fontdict=None, **kwargs): self._add_text(t) return t - @cbook._rename_parameter("3.3", "s", "text") + @_api.rename_parameter("3.3", "s", "text") @docstring.dedent_interpd def annotate(self, text, xy, *args, **kwargs): a = mtext.Annotation(text, xy, *args, **kwargs) diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 0947c6545d7d..c319557c80a9 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -33,7 +33,7 @@ warn_external as _warn_external, classproperty as _classproperty) from matplotlib._api.deprecation import ( deprecated, warn_deprecated, - _rename_parameter, _delete_parameter, _make_keyword_only, + _delete_parameter, _make_keyword_only, _deprecate_method_override, _deprecate_privatize_attribute, MatplotlibDeprecationWarning, mplDeprecation) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 0d7d5641248f..4129a620fd59 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -73,8 +73,8 @@ _code_objs = { - cbook._rename_parameter: - cbook._rename_parameter("", "old", "new", lambda new: None).__code__, + _api.rename_parameter: + _api.rename_parameter("", "old", "new", lambda new: None).__code__, cbook._make_keyword_only: cbook._make_keyword_only("", "p", lambda p: None).__code__, } @@ -84,9 +84,9 @@ def _copy_docstring_and_deprecators(method, func=None): if func is None: return functools.partial(_copy_docstring_and_deprecators, method) decorators = [docstring.copy(method)] - # Check whether the definition of *method* includes _rename_parameter or - # _make_keyword_only decorators; if so, propagate them to the pyplot - # wrapper as well. + # Check whether the definition of *method* includes @_api.rename_parameter + # or @_api._make_keyword_only decorators; if so, propagate them to the + # pyplot wrapper as well. while getattr(method, "__wrapped__", None) is not None: for decorator_maker, code in _code_objs.items(): if method.__code__ is code: diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index 57d97d791d3c..a5f781345242 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -194,7 +194,7 @@ def set_default_locators_and_formatters(self, axis): class LogTransform(Transform): input_dims = output_dims = 1 - @cbook._rename_parameter("3.3", "nonpos", "nonpositive") + @_api.rename_parameter("3.3", "nonpos", "nonpositive") def __init__(self, base, nonpositive='clip'): super().__init__() if base <= 0 or base == 1: @@ -287,9 +287,9 @@ def __init__(self, axis, **kwargs): # The following is to emit the right warnings depending on the axis # used, as the *old* kwarg names depended on the axis. axis_name = getattr(axis, "axis_name", "x") - @cbook._rename_parameter("3.3", f"base{axis_name}", "base") - @cbook._rename_parameter("3.3", f"subs{axis_name}", "subs") - @cbook._rename_parameter("3.3", f"nonpos{axis_name}", "nonpositive") + @_api.rename_parameter("3.3", f"base{axis_name}", "base") + @_api.rename_parameter("3.3", f"subs{axis_name}", "subs") + @_api.rename_parameter("3.3", f"nonpos{axis_name}", "nonpositive") def __init__(*, base=10, subs=None, nonpositive="clip"): return base, subs, nonpositive @@ -466,10 +466,10 @@ def InvertedSymmetricalLogTransform(self): def __init__(self, axis, **kwargs): axis_name = getattr(axis, "axis_name", "x") # See explanation in LogScale.__init__. - @cbook._rename_parameter("3.3", f"base{axis_name}", "base") - @cbook._rename_parameter("3.3", f"linthresh{axis_name}", "linthresh") - @cbook._rename_parameter("3.3", f"subs{axis_name}", "subs") - @cbook._rename_parameter("3.3", f"linscale{axis_name}", "linscale") + @_api.rename_parameter("3.3", f"base{axis_name}", "base") + @_api.rename_parameter("3.3", f"linthresh{axis_name}", "linthresh") + @_api.rename_parameter("3.3", f"subs{axis_name}", "subs") + @_api.rename_parameter("3.3", f"linscale{axis_name}", "linscale") def __init__(*, base=10, linthresh=2, subs=None, linscale=1): return base, linthresh, subs, linscale @@ -497,7 +497,7 @@ def get_transform(self): class LogitTransform(Transform): input_dims = output_dims = 1 - @cbook._rename_parameter("3.3", "nonpos", "nonpositive") + @_api.rename_parameter("3.3", "nonpos", "nonpositive") def __init__(self, nonpositive='mask'): super().__init__() _api.check_in_list(['mask', 'clip'], nonpositive=nonpositive) @@ -523,7 +523,7 @@ def __str__(self): class LogisticTransform(Transform): input_dims = output_dims = 1 - @cbook._rename_parameter("3.3", "nonpos", "nonpositive") + @_api.rename_parameter("3.3", "nonpos", "nonpositive") def __init__(self, nonpositive='mask'): super().__init__() self._nonpositive = nonpositive @@ -548,7 +548,7 @@ class LogitScale(ScaleBase): """ name = 'logit' - @cbook._rename_parameter("3.3", "nonpos", "nonpositive") + @_api.rename_parameter("3.3", "nonpos", "nonpositive") def __init__(self, axis, nonpositive='mask', *, one_half=r"\frac{1}{2}", use_overline=False): r""" diff --git a/lib/matplotlib/tests/test_pyplot.py b/lib/matplotlib/tests/test_pyplot.py index 57b7d7f2dea0..6b520aea30d4 100644 --- a/lib/matplotlib/tests/test_pyplot.py +++ b/lib/matplotlib/tests/test_pyplot.py @@ -39,8 +39,8 @@ def test_pyplot_up_to_date(tmpdir): def test_copy_docstring_and_deprecators(recwarn): - @mpl.cbook._rename_parameter("(version)", "old", "new") - @mpl.cbook._make_keyword_only("(version)", "kwo") + @mpl._api.rename_parameter("(version)", "old", "new") + @mpl._api.make_keyword_only("(version)", "kwo") def func(new, kwo=None): pass diff --git a/lib/mpl_toolkits/axisartist/angle_helper.py b/lib/mpl_toolkits/axisartist/angle_helper.py index d5e313988cfc..041bf443b766 100644 --- a/lib/mpl_toolkits/axisartist/angle_helper.py +++ b/lib/mpl_toolkits/axisartist/angle_helper.py @@ -1,7 +1,7 @@ import numpy as np import math -from matplotlib import _api, cbook +from matplotlib import _api from mpl_toolkits.axisartist.grid_finder import ExtremeFinderSimple @@ -141,7 +141,7 @@ def select_step360(v1, v2, nv, include_last=True, threshold_factor=3600): class LocatorBase: - @cbook._rename_parameter("3.3", "den", "nbins") + @_api.rename_parameter("3.3", "den", "nbins") def __init__(self, nbins, include_last=True): self.nbins = nbins self._include_last = include_last From 76709a4311b79d79566f4dc246544b4fde87c0b9 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 17 Dec 2020 01:36:28 +0100 Subject: [PATCH 2/3] Move internal usage from cbook._make_keyword_only to _api.make_keyword_only --- lib/matplotlib/_api/__init__.py | 2 +- lib/matplotlib/_api/deprecation.py | 4 ++-- lib/matplotlib/axes/_base.py | 2 +- lib/matplotlib/axis.py | 4 ++-- lib/matplotlib/cbook/__init__.py | 2 +- lib/matplotlib/colorbar.py | 2 +- lib/matplotlib/figure.py | 3 ++- lib/matplotlib/pyplot.py | 10 +++++----- lib/matplotlib/tests/test_api.py | 13 +++++++++++++ lib/matplotlib/tests/test_cbook.py | 13 ------------- 10 files changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/matplotlib/_api/__init__.py b/lib/matplotlib/_api/__init__.py index b366e7a3afba..ac3b86f2240a 100644 --- a/lib/matplotlib/_api/__init__.py +++ b/lib/matplotlib/_api/__init__.py @@ -17,7 +17,7 @@ from .deprecation import ( deprecated, warn_deprecated, - rename_parameter, _delete_parameter, _make_keyword_only, + rename_parameter, _delete_parameter, make_keyword_only, _deprecate_method_override, _deprecate_privatize_attribute, suppress_matplotlib_deprecation_warning, MatplotlibDeprecationWarning) diff --git a/lib/matplotlib/_api/deprecation.py b/lib/matplotlib/_api/deprecation.py index 63aee8592b35..2270cec2b2d7 100644 --- a/lib/matplotlib/_api/deprecation.py +++ b/lib/matplotlib/_api/deprecation.py @@ -433,14 +433,14 @@ def wrapper(*inner_args, **inner_kwargs): return wrapper -def _make_keyword_only(since, name, func=None): +def make_keyword_only(since, name, func=None): """ Decorator indicating that passing parameter *name* (or any of the following ones) positionally to *func* is being deprecated. """ if func is None: - return functools.partial(_make_keyword_only, since, name) + return functools.partial(make_keyword_only, since, name) signature = inspect.signature(func) POK = inspect.Parameter.POSITIONAL_OR_KEYWORD diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e353970b40c7..e7d2d72e1c42 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -465,7 +465,7 @@ def __str__(self): return "{0}({1[0]:g},{1[1]:g};{1[2]:g}x{1[3]:g})".format( type(self).__name__, self._position.bounds) - @cbook._make_keyword_only("3.4", "facecolor") + @_api.make_keyword_only("3.4", "facecolor") def __init__(self, fig, rect, facecolor=None, # defaults to rc axes.facecolor frameon=True, diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 1749b2e5a81b..5f6647981747 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1266,7 +1266,7 @@ def get_minorticklocs(self): if ~np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any()] return minor_locs - @cbook._make_keyword_only("3.3", "minor") + @_api.make_keyword_only("3.3", "minor") def get_ticklocs(self, minor=False): """Return this Axis' tick locations in data coordinates.""" return self.get_minorticklocs() if minor else self.get_majorticklocs() @@ -1738,7 +1738,7 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): # Wrapper around set_ticklabels used to generate Axes.set_x/ytickabels; can # go away once the API of Axes.set_x/yticklabels becomes consistent. - @cbook._make_keyword_only("3.3", "fontdict") + @_api.make_keyword_only("3.3", "fontdict") def _set_ticklabels(self, labels, fontdict=None, minor=False, **kwargs): """ Set this Axis' labels with list of string labels. diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index c319557c80a9..e27f5a5b0523 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -33,7 +33,7 @@ warn_external as _warn_external, classproperty as _classproperty) from matplotlib._api.deprecation import ( deprecated, warn_deprecated, - _delete_parameter, _make_keyword_only, + _delete_parameter, _deprecate_method_override, _deprecate_privatize_attribute, MatplotlibDeprecationWarning, mplDeprecation) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index a1e1c5f09669..22e6448debb7 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -411,7 +411,7 @@ class ColorbarBase: n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize - @cbook._make_keyword_only("3.3", "cmap") + @_api.make_keyword_only("3.3", "cmap") def __init__(self, ax, cmap=None, norm=None, alpha=None, diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index e6b858fb5298..f4ca253c1341 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -29,6 +29,7 @@ Artist, allow_rasterization, _finalize_rasterization) from matplotlib.backend_bases import ( FigureCanvasBase, NonGuiException, MouseButton) +import matplotlib._api as _api import matplotlib.cbook as cbook import matplotlib.colorbar as cbar import matplotlib.image as mimage @@ -887,7 +888,7 @@ def _add_axes_internal(self, key, ax): ax.stale_callback = _stale_figure_callback return ax - @cbook._make_keyword_only("3.3", "sharex") + @_api.make_keyword_only("3.3", "sharex") def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None): """ diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 4129a620fd59..277735d451d0 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -75,8 +75,8 @@ _code_objs = { _api.rename_parameter: _api.rename_parameter("", "old", "new", lambda new: None).__code__, - cbook._make_keyword_only: - cbook._make_keyword_only("", "p", lambda p: None).__code__, + _api.make_keyword_only: + _api.make_keyword_only("", "p", lambda p: None).__code__, } @@ -85,7 +85,7 @@ def _copy_docstring_and_deprecators(method, func=None): return functools.partial(_copy_docstring_and_deprecators, method) decorators = [docstring.copy(method)] # Check whether the definition of *method* includes @_api.rename_parameter - # or @_api._make_keyword_only decorators; if so, propagate them to the + # or @_api.make_keyword_only decorators; if so, propagate them to the # pyplot wrapper as well. while getattr(method, "__wrapped__", None) is not None: for decorator_maker, code in _code_objs.items(): @@ -1236,7 +1236,7 @@ def subplot(*args, **kwargs): return ax -@cbook._make_keyword_only("3.3", "sharex") +@_api.make_keyword_only("3.3", "sharex") def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw): """ @@ -1574,7 +1574,7 @@ def subplot_tool(targetfig=None): # After deprecation elapses, this can be autogenerated by boilerplate.py. -@cbook._make_keyword_only("3.3", "pad") +@_api.make_keyword_only("3.3", "pad") def tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None): """ Adjust the padding between and around subplots. diff --git a/lib/matplotlib/tests/test_api.py b/lib/matplotlib/tests/test_api.py index 5df3e4f75a2d..331fca827bf1 100644 --- a/lib/matplotlib/tests/test_api.py +++ b/lib/matplotlib/tests/test_api.py @@ -32,3 +32,16 @@ def f(cls): with pytest.warns(_api.MatplotlibDeprecationWarning): a = A() a.f + + +def test_make_keyword_only(): + @_api.make_keyword_only("3.0", "arg") + def func(pre, arg, post=None): + pass + + func(1, arg=2) # Check that no warning is emitted. + + with pytest.warns(_api.MatplotlibDeprecationWarning): + func(1, 2) + with pytest.warns(_api.MatplotlibDeprecationWarning): + func(1, 2, 3) diff --git a/lib/matplotlib/tests/test_cbook.py b/lib/matplotlib/tests/test_cbook.py index 419dabecb880..52d8305262b8 100644 --- a/lib/matplotlib/tests/test_cbook.py +++ b/lib/matplotlib/tests/test_cbook.py @@ -628,19 +628,6 @@ def pyplot_wrapper(foo=_api.deprecation._deprecated_parameter): func(foo="bar") -def test_make_keyword_only(): - @cbook._make_keyword_only("3.0", "arg") - def func(pre, arg, post=None): - pass - - func(1, arg=2) # Check that no warning is emitted. - - with pytest.warns(MatplotlibDeprecationWarning): - func(1, 2) - with pytest.warns(MatplotlibDeprecationWarning): - func(1, 2, 3) - - def test_warn_external(recwarn): cbook._warn_external("oops") assert len(recwarn) == 1 From 410c51d6cb6887215558956eb0dcf5e7c96ec401 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 17 Dec 2020 02:05:24 +0100 Subject: [PATCH 3/3] Move internal usage from cbook._delete_parameter to _api.delete_parameter --- lib/matplotlib/__init__.py | 2 +- lib/matplotlib/_api/__init__.py | 2 +- lib/matplotlib/_api/deprecation.py | 6 +++--- lib/matplotlib/_mathtext.py | 2 +- lib/matplotlib/animation.py | 2 +- lib/matplotlib/artist.py | 6 +++--- lib/matplotlib/axes/_base.py | 2 +- lib/matplotlib/axis.py | 2 +- lib/matplotlib/backend_bases.py | 2 +- lib/matplotlib/backend_managers.py | 5 ++--- lib/matplotlib/backends/_backend_tk.py | 2 +- lib/matplotlib/backends/backend_agg.py | 12 ++++++------ lib/matplotlib/backends/backend_pdf.py | 2 +- lib/matplotlib/backends/backend_pgf.py | 2 +- lib/matplotlib/backends/backend_ps.py | 2 +- lib/matplotlib/backends/backend_svg.py | 2 +- lib/matplotlib/backends/backend_wx.py | 2 +- lib/matplotlib/cbook/__init__.py | 9 ++++----- lib/matplotlib/collections.py | 2 +- lib/matplotlib/gridspec.py | 2 +- lib/matplotlib/offsetbox.py | 4 ++-- lib/matplotlib/patches.py | 10 +++++----- lib/matplotlib/path.py | 4 ++-- lib/matplotlib/projections/polar.py | 4 ++-- lib/matplotlib/scale.py | 2 +- lib/matplotlib/tests/test_api.py | 22 ++++++++++++++++++++++ lib/matplotlib/tests/test_cbook.py | 24 +----------------------- lib/mpl_toolkits/axes_grid1/axes_grid.py | 4 ++-- lib/mpl_toolkits/axes_grid1/axes_rgb.py | 6 +++--- lib/mpl_toolkits/mplot3d/art3d.py | 15 ++++++++------- 30 files changed, 81 insertions(+), 82 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index b8a747acafd6..e43169dca5d5 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1194,7 +1194,7 @@ def _init_tests(): "" if ft2font.__freetype_build_type__ == 'local' else "not ")) -@cbook._delete_parameter("3.3", "recursionlimit") +@_api.delete_parameter("3.3", "recursionlimit") def test(verbosity=None, coverage=False, *, recursionlimit=0, **kwargs): """Run the matplotlib test suite.""" diff --git a/lib/matplotlib/_api/__init__.py b/lib/matplotlib/_api/__init__.py index ac3b86f2240a..487fa1d22f36 100644 --- a/lib/matplotlib/_api/__init__.py +++ b/lib/matplotlib/_api/__init__.py @@ -17,7 +17,7 @@ from .deprecation import ( deprecated, warn_deprecated, - rename_parameter, _delete_parameter, make_keyword_only, + rename_parameter, delete_parameter, make_keyword_only, _deprecate_method_override, _deprecate_privatize_attribute, suppress_matplotlib_deprecation_warning, MatplotlibDeprecationWarning) diff --git a/lib/matplotlib/_api/deprecation.py b/lib/matplotlib/_api/deprecation.py index 2270cec2b2d7..fb647d496e06 100644 --- a/lib/matplotlib/_api/deprecation.py +++ b/lib/matplotlib/_api/deprecation.py @@ -350,7 +350,7 @@ def __repr__(self): _deprecated_parameter = _deprecated_parameter_class() -def _delete_parameter(since, name, func=None, **kwargs): +def delete_parameter(since, name, func=None, **kwargs): """ Decorator indicating that parameter *name* of *func* is being deprecated. @@ -371,12 +371,12 @@ def _delete_parameter(since, name, func=None, **kwargs): -------- :: - @_delete_parameter("3.1", "unused") + @_api.delete_parameter("3.1", "unused") def func(used_arg, other_arg, unused, more_args): ... """ if func is None: - return functools.partial(_delete_parameter, since, name, **kwargs) + return functools.partial(delete_parameter, since, name, **kwargs) signature = inspect.signature(func) # Name of `**kwargs` parameter of the decorated function, typically diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index a3de051240f6..a97615df775e 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -1551,7 +1551,7 @@ class Glue(Node): glue_subtype = cbook.deprecated("3.3")(property(lambda self: "normal")) - @cbook._delete_parameter("3.3", "copy") + @_api.delete_parameter("3.3", "copy") def __init__(self, glue_type, copy=False): super().__init__() if isinstance(glue_type, str): diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 48a3ae41ed09..3bf6cc1b601f 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -407,7 +407,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.frame_format = mpl.rcParams['animation.frame_format'] - @cbook._delete_parameter("3.3", "clear_temp") + @_api.delete_parameter("3.3", "clear_temp") def setup(self, fig, outfile, dpi=None, frame_prefix=None, clear_temp=True): """ diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index b3251e60f191..1f36fd1190bb 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -28,7 +28,7 @@ def allow_rasterization(draw): # Axes has a second (deprecated) argument inframe for its draw method. # args and kwargs are deprecated, but we don't wrap this in - # cbook._delete_parameter for performance; the relevant deprecation + # _api.delete_parameter for performance; the relevant deprecation # warning will be emitted by the inner draw() call. @wraps(draw) def draw_wrapper(artist, renderer, *args, **kwargs): @@ -926,8 +926,8 @@ def set_agg_filter(self, filter_func): self._agg_filter = filter_func self.stale = True - @cbook._delete_parameter("3.3", "args") - @cbook._delete_parameter("3.3", "kwargs") + @_api.delete_parameter("3.3", "args") + @_api.delete_parameter("3.3", "kwargs") def draw(self, renderer, *args, **kwargs): """ Draw the Artist (and its children) using the given renderer. diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e7d2d72e1c42..1583c92b7ce4 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2743,7 +2743,7 @@ def _update_title_position(self, renderer): # Drawing @martist.allow_rasterization - @cbook._delete_parameter( + @_api.delete_parameter( "3.3", "inframe", alternative="Axes.redraw_in_frame()") def draw(self, renderer=None, inframe=False): # docstring inherited diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 5f6647981747..2724cd7b1a02 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -54,7 +54,7 @@ class Tick(martist.Artist): The right/top tick label. """ - @cbook._delete_parameter("3.3", "label") + @_api.delete_parameter("3.3", "label") def __init__(self, axes, loc, label=None, size=None, # points width=None, diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 477c11095752..6e5896765fc5 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -535,7 +535,7 @@ def option_scale_image(self): """ return False - @cbook._delete_parameter("3.3", "ismath") + @_api.delete_parameter("3.3", "ismath") def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None): """ """ diff --git a/lib/matplotlib/backend_managers.py b/lib/matplotlib/backend_managers.py index ce9809aada58..951978a3a06a 100644 --- a/lib/matplotlib/backend_managers.py +++ b/lib/matplotlib/backend_managers.py @@ -1,7 +1,6 @@ import logging -import matplotlib.cbook as cbook -import matplotlib.widgets as widgets +from matplotlib import _api, cbook, widgets from matplotlib.rcsetup import validate_stringlist import matplotlib.backend_tools as tools @@ -183,7 +182,7 @@ def _remove_keys(self, name): for k in self.get_tool_keymap(name): del self._keys[k] - @cbook._delete_parameter("3.3", "args") + @_api.delete_parameter("3.3", "args") def update_keymap(self, name, key, *args): """ Set the keymap to associate with the specified tool. diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index 59426804943a..fae85bf9009f 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -159,7 +159,7 @@ def _on_timer(self): class FigureCanvasTk(FigureCanvasBase): required_interactive_framework = "tk" - @cbook._delete_parameter( + @_api.delete_parameter( "3.4", "resize_callback", alternative="get_tk_widget().bind('', ..., True)") def __init__(self, figure, master=None, resize_callback=None): diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index 16c5e64d0ae4..f4b15871f10d 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -522,12 +522,12 @@ def print_to_buffer(self): @_check_savefig_extra_args( extra_kwargs=["quality", "optimize", "progressive"]) - @cbook._delete_parameter("3.3", "quality", - alternative="pil_kwargs={'quality': ...}") - @cbook._delete_parameter("3.3", "optimize", - alternative="pil_kwargs={'optimize': ...}") - @cbook._delete_parameter("3.3", "progressive", - alternative="pil_kwargs={'progressive': ...}") + @_api.delete_parameter("3.3", "quality", + alternative="pil_kwargs={'quality': ...}") + @_api.delete_parameter("3.3", "optimize", + alternative="pil_kwargs={'optimize': ...}") + @_api.delete_parameter("3.3", "progressive", + alternative="pil_kwargs={'progressive': ...}") def print_jpg(self, filename_or_obj, *args, pil_kwargs=None, **kwargs): """ Write the figure to a JPEG file. diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index eafb0048c23e..903d78c7c99c 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -2155,7 +2155,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle): # Pop off the global transformation self.file.output(Op.grestore) - @cbook._delete_parameter("3.3", "ismath") + @_api.delete_parameter("3.3", "ismath") def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None): # docstring inherited texmanager = self.get_texmanager() diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index a670788b5360..54f19b7d9c32 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -380,7 +380,7 @@ def _get_image_inclusion_command(): class RendererPgf(RendererBase): - @cbook._delete_parameter("3.3", "dummy") + @_api.delete_parameter("3.3", "dummy") def __init__(self, figure, fh, dummy=False): """ Create a new PGF renderer that translates any drawing instruction diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 11a005ee8bf6..ceadbc074963 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -554,7 +554,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms, self._path_collection_id += 1 - @cbook._delete_parameter("3.3", "ismath") + @_api.delete_parameter("3.3", "ismath") def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None): # docstring inherited if not hasattr(self, "psfrag"): diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index 79e2be045abb..ce6ad0c115f8 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -1238,7 +1238,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None): writer.end('g') - @cbook._delete_parameter("3.3", "ismath") + @_api.delete_parameter("3.3", "ismath") def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None): # docstring inherited self._draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX") diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index 5e83baf8df70..02ccdd8c4342 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -599,7 +599,7 @@ def _get_imagesave_wildcards(self): wildcards = '|'.join(wildcards) return wildcards, extensions, filter_index - @cbook._delete_parameter("3.4", "origin") + @_api.delete_parameter("3.4", "origin") def gui_repaint(self, drawDC=None, origin='WX'): """ Performs update of the displayed image on the GUI canvas, using the diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index e27f5a5b0523..c7ca110a0e04 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -28,12 +28,11 @@ import numpy as np import matplotlib -from matplotlib import _c_internal_utils +from matplotlib import _api, _c_internal_utils from matplotlib._api import ( warn_external as _warn_external, classproperty as _classproperty) from matplotlib._api.deprecation import ( deprecated, warn_deprecated, - _delete_parameter, _deprecate_method_override, _deprecate_privatize_attribute, MatplotlibDeprecationWarning, mplDeprecation) @@ -1704,9 +1703,9 @@ def sanitize_sequence(data): else data) -@_delete_parameter("3.3", "required") -@_delete_parameter("3.3", "forbidden") -@_delete_parameter("3.3", "allowed") +@_api.delete_parameter("3.3", "required") +@_api.delete_parameter("3.3", "forbidden") +@_api.delete_parameter("3.3", "allowed") def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(), allowed=None): """ diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 8aed4182b00f..37644e426d58 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -70,7 +70,7 @@ class Collection(artist.Artist, cm.ScalarMappable): # subclass-by-subclass basis. _edge_default = False - @cbook._delete_parameter("3.3", "offset_position") + @_api.delete_parameter("3.3", "offset_position") def __init__(self, edgecolors=None, facecolors=None, diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index c742aef0c8ba..049a13ec922a 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -723,7 +723,7 @@ def is_first_col(self): def is_last_col(self): return self.colspan.stop == self.get_gridspec().ncols - @cbook._delete_parameter("3.4", "return_all") + @_api.delete_parameter("3.4", "return_all") def get_position(self, figure, return_all=False): """ Update the subplot position from ``figure.subplotpars``. diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index dcf7d9c7c34e..4fc37fe30b81 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -706,7 +706,7 @@ class TextArea(OffsetBox): child text. """ - @cbook._delete_parameter("3.4", "minimumdescent") + @_api.delete_parameter("3.4", "minimumdescent") def __init__(self, s, textprops=None, multilinebaseline=False, @@ -1480,7 +1480,7 @@ def set_fontsize(self, s=None): self.prop = FontProperties(size=s) self.stale = True - @cbook._delete_parameter("3.3", "s") + @_api.delete_parameter("3.3", "s") def get_fontsize(self, s=None): """Return the fontsize in points.""" return self.prop.get_size_in_points() diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 103adee18366..89ee6d23824c 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -638,7 +638,7 @@ class Shadow(Patch): def __str__(self): return "Shadow(%s)" % (str(self.patch)) - @cbook._delete_parameter("3.3", "props") + @_api.delete_parameter("3.3", "props") @docstring.dedent_interpd def __init__(self, patch, ox, oy, props=None, **kwargs): """ @@ -2014,7 +2014,7 @@ def __init_subclass__(cls): __call__ = cls.__call__ - @cbook._delete_parameter("3.4", "mutation_aspect") + @_api.delete_parameter("3.4", "mutation_aspect") def call_wrapper( self, x0, y0, width, height, mutation_size, mutation_aspect=_api.deprecation._deprecated_parameter): @@ -3602,7 +3602,7 @@ def __str__(self): return s % (self._x, self._y, self._width, self._height) @docstring.dedent_interpd - @cbook._delete_parameter("3.4", "bbox_transmuter", alternative="boxstyle") + @_api.delete_parameter("3.4", "bbox_transmuter", alternative="boxstyle") def __init__(self, xy, width, height, boxstyle="round", bbox_transmuter=None, mutation_scale=1, mutation_aspect=1, @@ -3893,7 +3893,7 @@ def __str__(self): return f"{type(self).__name__}({self._path_original})" @docstring.dedent_interpd - @cbook._delete_parameter("3.4", "dpi_cor") + @_api.delete_parameter("3.4", "dpi_cor") def __init__(self, posA=None, posB=None, path=None, arrowstyle="simple", connectionstyle="arc3", patchA=None, patchB=None, @@ -4240,7 +4240,7 @@ def __str__(self): (self.xy1[0], self.xy1[1], self.xy2[0], self.xy2[1]) @docstring.dedent_interpd - @cbook._delete_parameter("3.4", "dpi_cor") + @_api.delete_parameter("3.4", "dpi_cor") def __init__(self, xyA, xyB, coordsA, coordsB=None, axesA=None, axesB=None, arrowstyle="-", diff --git a/lib/matplotlib/path.py b/lib/matplotlib/path.py index 972b6d2ec0d1..1e13168ccd51 100644 --- a/lib/matplotlib/path.py +++ b/lib/matplotlib/path.py @@ -15,7 +15,7 @@ import numpy as np import matplotlib as mpl -from . import _api, _path, cbook +from . import _api, _path from .cbook import _to_unmasked_float_array, simple_linear_interpolation from .bezier import BezierSegment @@ -461,7 +461,7 @@ def iter_bezier(self, **kwargs): raise ValueError("Invalid Path.code_type: " + str(code)) prev_vert = verts[-2:] - @cbook._delete_parameter("3.3", "quantize") + @_api.delete_parameter("3.3", "quantize") def cleaned(self, transform=None, remove_nans=False, clip=None, quantize=False, simplify=False, curves=False, stroke_width=1.0, snap=False, sketch=None): diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index 965da628b0a9..41b13ee808cc 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -945,8 +945,8 @@ def get_yaxis_text2_transform(self, pad): pad_shift = _ThetaShift(self, pad, 'min') return self._yaxis_text_transform + pad_shift, 'center', halign - @cbook._delete_parameter("3.3", "args") - @cbook._delete_parameter("3.3", "kwargs") + @_api.delete_parameter("3.3", "args") + @_api.delete_parameter("3.3", "kwargs") def draw(self, renderer, *args, **kwargs): self._unstale_viewLim() thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx) diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index a5f781345242..7c90369250d0 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -14,7 +14,7 @@ from numpy import ma import matplotlib as mpl -from matplotlib import _api, cbook, docstring +from matplotlib import _api, docstring from matplotlib.ticker import ( NullFormatter, ScalarFormatter, LogFormatterSciNotation, LogitFormatter, NullLocator, LogLocator, AutoLocator, AutoMinorLocator, diff --git a/lib/matplotlib/tests/test_api.py b/lib/matplotlib/tests/test_api.py index 331fca827bf1..29ca4caf5ca0 100644 --- a/lib/matplotlib/tests/test_api.py +++ b/lib/matplotlib/tests/test_api.py @@ -34,6 +34,28 @@ def f(cls): a.f +def test_delete_parameter(): + @_api.delete_parameter("3.0", "foo") + def func1(foo=None): + pass + + @_api.delete_parameter("3.0", "foo") + def func2(**kwargs): + pass + + for func in [func1, func2]: + func() # No warning. + with pytest.warns(_api.MatplotlibDeprecationWarning): + func(foo="bar") + + def pyplot_wrapper(foo=_api.deprecation._deprecated_parameter): + func1(foo) + + pyplot_wrapper() # No warning. + with pytest.warns(_api.MatplotlibDeprecationWarning): + func(foo="bar") + + def test_make_keyword_only(): @_api.make_keyword_only("3.0", "arg") def func(pre, arg, post=None): diff --git a/lib/matplotlib/tests/test_cbook.py b/lib/matplotlib/tests/test_cbook.py index 52d8305262b8..bc772eba5a96 100644 --- a/lib/matplotlib/tests/test_cbook.py +++ b/lib/matplotlib/tests/test_cbook.py @@ -14,7 +14,7 @@ from matplotlib import _api import matplotlib.cbook as cbook import matplotlib.colors as mcolors -from matplotlib.cbook import MatplotlibDeprecationWarning, delete_masked_points +from matplotlib.cbook import delete_masked_points class Test_delete_masked_points: @@ -606,28 +606,6 @@ def test_safe_first_element_pandas_series(pd): assert actual == 0 -def test_delete_parameter(): - @cbook._delete_parameter("3.0", "foo") - def func1(foo=None): - pass - - @cbook._delete_parameter("3.0", "foo") - def func2(**kwargs): - pass - - for func in [func1, func2]: - func() # No warning. - with pytest.warns(MatplotlibDeprecationWarning): - func(foo="bar") - - def pyplot_wrapper(foo=_api.deprecation._deprecated_parameter): - func1(foo) - - pyplot_wrapper() # No warning. - with pytest.warns(MatplotlibDeprecationWarning): - func(foo="bar") - - def test_warn_external(recwarn): cbook._warn_external("oops") assert len(recwarn) == 1 diff --git a/lib/mpl_toolkits/axes_grid1/axes_grid.py b/lib/mpl_toolkits/axes_grid1/axes_grid.py index f38e0643ed8d..d91d710a7077 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_grid.py +++ b/lib/mpl_toolkits/axes_grid1/axes_grid.py @@ -80,7 +80,7 @@ class Grid: _defaultAxesClass = Axes - @cbook._delete_parameter("3.3", "add_all") + @_api.delete_parameter("3.3", "add_all") def __init__(self, fig, rect, nrows_ncols, @@ -335,7 +335,7 @@ class ImageGrid(Grid): _defaultCbarAxesClass = CbarAxes - @cbook._delete_parameter("3.3", "add_all") + @_api.delete_parameter("3.3", "add_all") def __init__(self, fig, rect, nrows_ncols, diff --git a/lib/mpl_toolkits/axes_grid1/axes_rgb.py b/lib/mpl_toolkits/axes_grid1/axes_rgb.py index 7ea73515fae6..f111798ae6df 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_rgb.py +++ b/lib/mpl_toolkits/axes_grid1/axes_rgb.py @@ -1,11 +1,11 @@ import numpy as np -from matplotlib import _api, cbook +from matplotlib import _api from .axes_divider import make_axes_locatable, Size from .mpl_axes import Axes -@cbook._delete_parameter("3.3", "add_all") +@_api.delete_parameter("3.3", "add_all") def make_rgb_axes(ax, pad=0.01, axes_class=None, add_all=True, **kwargs): """ Parameters @@ -91,7 +91,7 @@ class RGBAxes: _defaultAxesClass = Axes - @cbook._delete_parameter("3.3", "add_all") + @_api.delete_parameter("3.3", "add_all") def __init__(self, *args, pad=0, add_all=True, **kwargs): """ Parameters diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index c5a01df0e5d4..a7e2619ae0ca 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -12,7 +12,8 @@ import numpy as np from matplotlib import ( - artist, cbook, colors as mcolors, lines, text as mtext, path as mpath) + _api, artist, cbook, colors as mcolors, lines, text as mtext, + path as mpath) from matplotlib.collections import ( LineCollection, PolyCollection, PatchCollection, PathCollection) from matplotlib.colors import Normalize @@ -296,7 +297,7 @@ def set_segments(self, segments): self._segments3d = segments super().set_segments([]) - @cbook._delete_parameter('3.4', 'renderer') + @_api.delete_parameter('3.4', 'renderer') def do_3d_projection(self, renderer=None): """ Project the points according to renderer matrix. @@ -349,7 +350,7 @@ def get_path(self): def get_facecolor(self): return self._facecolor2d - @cbook._delete_parameter('3.4', 'renderer') + @_api.delete_parameter('3.4', 'renderer') def do_3d_projection(self, renderer=None): s = self._segment3d xs, ys, zs = zip(*s) @@ -375,7 +376,7 @@ def set_3d_properties(self, path, zs=0, zdir='z'): Patch3D.set_3d_properties(self, path.vertices, zs=zs, zdir=zdir) self._code3d = path.codes - @cbook._delete_parameter('3.4', 'renderer') + @_api.delete_parameter('3.4', 'renderer') def do_3d_projection(self, renderer=None): s = self._segment3d xs, ys, zs = zip(*s) @@ -486,7 +487,7 @@ def set_3d_properties(self, zs, zdir): self._edgecolor3d = self.get_edgecolor() self.stale = True - @cbook._delete_parameter('3.4', 'renderer') + @_api.delete_parameter('3.4', 'renderer') def do_3d_projection(self, renderer=None): # see _update_scalarmappable docstring for why this must be here _update_scalarmappable(self) @@ -594,7 +595,7 @@ def set_linewidth(self, lw): super().set_linewidth(lw) self._linewidth3d = self.get_linewidth() - @cbook._delete_parameter('3.4', 'renderer') + @_api.delete_parameter('3.4', 'renderer') def do_3d_projection(self, renderer=None): # see _update_scalarmappable docstring for why this must be here _update_scalarmappable(self) @@ -844,7 +845,7 @@ def set_sort_zpos(self, val): self._sort_zpos = val self.stale = True - @cbook._delete_parameter('3.4', 'renderer') + @_api.delete_parameter('3.4', 'renderer') def do_3d_projection(self, renderer=None): """ Perform the 3D projection for this object.