Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Move internal usage from cbook._rename_parameter to _api.rename_param…
…eter
  • Loading branch information
timhoffm committed Dec 17, 2020
commit 25331147b1017fd5e0b70a16f99029bfb0a0c46c
2 changes: 1 addition & 1 deletion lib/matplotlib/_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/_api/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*.

Expand All @@ -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, (
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__,
}
Expand All @@ -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:
Expand Down
22 changes: 11 additions & 11 deletions lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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"""
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/mpl_toolkits/axisartist/angle_helper.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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
Expand Down