Skip to content

Commit 76709a4

Browse files
committed
Move internal usage from cbook._make_keyword_only to _api.make_keyword_only
1 parent 2533114 commit 76709a4

File tree

10 files changed

+28
-27
lines changed

10 files changed

+28
-27
lines changed

lib/matplotlib/_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from .deprecation import (
1919
deprecated, warn_deprecated,
20-
rename_parameter, _delete_parameter, _make_keyword_only,
20+
rename_parameter, _delete_parameter, make_keyword_only,
2121
_deprecate_method_override, _deprecate_privatize_attribute,
2222
suppress_matplotlib_deprecation_warning,
2323
MatplotlibDeprecationWarning)

lib/matplotlib/_api/deprecation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,14 +433,14 @@ def wrapper(*inner_args, **inner_kwargs):
433433
return wrapper
434434

435435

436-
def _make_keyword_only(since, name, func=None):
436+
def make_keyword_only(since, name, func=None):
437437
"""
438438
Decorator indicating that passing parameter *name* (or any of the following
439439
ones) positionally to *func* is being deprecated.
440440
"""
441441

442442
if func is None:
443-
return functools.partial(_make_keyword_only, since, name)
443+
return functools.partial(make_keyword_only, since, name)
444444

445445
signature = inspect.signature(func)
446446
POK = inspect.Parameter.POSITIONAL_OR_KEYWORD

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def __str__(self):
465465
return "{0}({1[0]:g},{1[1]:g};{1[2]:g}x{1[3]:g})".format(
466466
type(self).__name__, self._position.bounds)
467467

468-
@cbook._make_keyword_only("3.4", "facecolor")
468+
@_api.make_keyword_only("3.4", "facecolor")
469469
def __init__(self, fig, rect,
470470
facecolor=None, # defaults to rc axes.facecolor
471471
frameon=True,

lib/matplotlib/axis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ def get_minorticklocs(self):
12661266
if ~np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any()]
12671267
return minor_locs
12681268

1269-
@cbook._make_keyword_only("3.3", "minor")
1269+
@_api.make_keyword_only("3.3", "minor")
12701270
def get_ticklocs(self, minor=False):
12711271
"""Return this Axis' tick locations in data coordinates."""
12721272
return self.get_minorticklocs() if minor else self.get_majorticklocs()
@@ -1738,7 +1738,7 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
17381738

17391739
# Wrapper around set_ticklabels used to generate Axes.set_x/ytickabels; can
17401740
# go away once the API of Axes.set_x/yticklabels becomes consistent.
1741-
@cbook._make_keyword_only("3.3", "fontdict")
1741+
@_api.make_keyword_only("3.3", "fontdict")
17421742
def _set_ticklabels(self, labels, fontdict=None, minor=False, **kwargs):
17431743
"""
17441744
Set this Axis' labels with list of string labels.

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
warn_external as _warn_external, classproperty as _classproperty)
3434
from matplotlib._api.deprecation import (
3535
deprecated, warn_deprecated,
36-
_delete_parameter, _make_keyword_only,
36+
_delete_parameter,
3737
_deprecate_method_override, _deprecate_privatize_attribute,
3838
MatplotlibDeprecationWarning, mplDeprecation)
3939

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class ColorbarBase:
411411

412412
n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize
413413

414-
@cbook._make_keyword_only("3.3", "cmap")
414+
@_api.make_keyword_only("3.3", "cmap")
415415
def __init__(self, ax, cmap=None,
416416
norm=None,
417417
alpha=None,

lib/matplotlib/figure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
Artist, allow_rasterization, _finalize_rasterization)
3030
from matplotlib.backend_bases import (
3131
FigureCanvasBase, NonGuiException, MouseButton)
32+
import matplotlib._api as _api
3233
import matplotlib.cbook as cbook
3334
import matplotlib.colorbar as cbar
3435
import matplotlib.image as mimage
@@ -887,7 +888,7 @@ def _add_axes_internal(self, key, ax):
887888
ax.stale_callback = _stale_figure_callback
888889
return ax
889890

890-
@cbook._make_keyword_only("3.3", "sharex")
891+
@_api.make_keyword_only("3.3", "sharex")
891892
def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
892893
squeeze=True, subplot_kw=None, gridspec_kw=None):
893894
"""

lib/matplotlib/pyplot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
_code_objs = {
7676
_api.rename_parameter:
7777
_api.rename_parameter("", "old", "new", lambda new: None).__code__,
78-
cbook._make_keyword_only:
79-
cbook._make_keyword_only("", "p", lambda p: None).__code__,
78+
_api.make_keyword_only:
79+
_api.make_keyword_only("", "p", lambda p: None).__code__,
8080
}
8181

8282

@@ -85,7 +85,7 @@ def _copy_docstring_and_deprecators(method, func=None):
8585
return functools.partial(_copy_docstring_and_deprecators, method)
8686
decorators = [docstring.copy(method)]
8787
# Check whether the definition of *method* includes @_api.rename_parameter
88-
# or @_api._make_keyword_only decorators; if so, propagate them to the
88+
# or @_api.make_keyword_only decorators; if so, propagate them to the
8989
# pyplot wrapper as well.
9090
while getattr(method, "__wrapped__", None) is not None:
9191
for decorator_maker, code in _code_objs.items():
@@ -1236,7 +1236,7 @@ def subplot(*args, **kwargs):
12361236
return ax
12371237

12381238

1239-
@cbook._make_keyword_only("3.3", "sharex")
1239+
@_api.make_keyword_only("3.3", "sharex")
12401240
def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
12411241
subplot_kw=None, gridspec_kw=None, **fig_kw):
12421242
"""
@@ -1574,7 +1574,7 @@ def subplot_tool(targetfig=None):
15741574

15751575

15761576
# After deprecation elapses, this can be autogenerated by boilerplate.py.
1577-
@cbook._make_keyword_only("3.3", "pad")
1577+
@_api.make_keyword_only("3.3", "pad")
15781578
def tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None):
15791579
"""
15801580
Adjust the padding between and around subplots.

lib/matplotlib/tests/test_api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ def f(cls):
3232
with pytest.warns(_api.MatplotlibDeprecationWarning):
3333
a = A()
3434
a.f
35+
36+
37+
def test_make_keyword_only():
38+
@_api.make_keyword_only("3.0", "arg")
39+
def func(pre, arg, post=None):
40+
pass
41+
42+
func(1, arg=2) # Check that no warning is emitted.
43+
44+
with pytest.warns(_api.MatplotlibDeprecationWarning):
45+
func(1, 2)
46+
with pytest.warns(_api.MatplotlibDeprecationWarning):
47+
func(1, 2, 3)

lib/matplotlib/tests/test_cbook.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -628,19 +628,6 @@ def pyplot_wrapper(foo=_api.deprecation._deprecated_parameter):
628628
func(foo="bar")
629629

630630

631-
def test_make_keyword_only():
632-
@cbook._make_keyword_only("3.0", "arg")
633-
def func(pre, arg, post=None):
634-
pass
635-
636-
func(1, arg=2) # Check that no warning is emitted.
637-
638-
with pytest.warns(MatplotlibDeprecationWarning):
639-
func(1, 2)
640-
with pytest.warns(MatplotlibDeprecationWarning):
641-
func(1, 2, 3)
642-
643-
644631
def test_warn_external(recwarn):
645632
cbook._warn_external("oops")
646633
assert len(recwarn) == 1

0 commit comments

Comments
 (0)