Skip to content

Switch internal API function calls from cbook to _api #19134

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 3 commits into from
Dec 17, 2020
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
2 changes: 1 addition & 1 deletion lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
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
18 changes: 9 additions & 9 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 @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
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
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
"""
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/backend_managers.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<Configure>', ..., True)")
def __init__(self, figure, master=None, resize_callback=None):
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
_rename_parameter, _delete_parameter, _make_keyword_only,
_deprecate_method_override, _deprecate_privatize_attribute,
MatplotlibDeprecationWarning, mplDeprecation)

Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/gridspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
Loading