Skip to content

Expire deprecations in cbook.deprecation #22514

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
Feb 25, 2022
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
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/removals/22514-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Removal of deprecations in ``cbook``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The module ``cbook.deprecation`` is removed from the public API as it is
considered internal. This also holds for deprecation-related re-imports in
``cbook``: ``deprecated``, ``MatplotlibDeprecationWarning``,
``mplDeprecation``, and ``warn_deprecated``.
4 changes: 2 additions & 2 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
# cbook must import matplotlib only within function
# definitions, so it is safe to import from it here.
from . import _api, _version, cbook, docstring, rcsetup
from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
from matplotlib.cbook import mplDeprecation # deprecated
from matplotlib.cbook import sanitize_sequence
from matplotlib._api import MatplotlibDeprecationWarning
from matplotlib.rcsetup import validate_backend, cycler


Expand Down
5 changes: 0 additions & 5 deletions lib/matplotlib/_api/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ class MatplotlibDeprecationWarning(DeprecationWarning):
"""A class for issuing deprecation warnings for Matplotlib users."""


# mplDeprecation is deprecated. Use MatplotlibDeprecationWarning instead.
# remove when removing the re-import from cbook
mplDeprecation = MatplotlibDeprecationWarning


def _generate_deprecation_warning(
since, message='', name='', alternative='', pending=False, obj_type='',
addendum='', *, removal=''):
Expand Down
15 changes: 2 additions & 13 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@

import matplotlib
from matplotlib import _api, _c_internal_utils
from matplotlib._api.deprecation import (
MatplotlibDeprecationWarning, mplDeprecation)


@_api.deprecated("3.4")
def deprecated(*args, **kwargs):
return _api.deprecated(*args, **kwargs)


@_api.deprecated("3.4")
def warn_deprecated(*args, **kwargs):
_api.warn_deprecated(*args, **kwargs)


def _get_running_interactive_framework():
Expand Down Expand Up @@ -365,7 +353,8 @@ def __repr__(self):


def _local_over_kwdict(
local_var, kwargs, *keys, warning_cls=MatplotlibDeprecationWarning):
local_var, kwargs, *keys,
warning_cls=_api.MatplotlibDeprecationWarning):
out = local_var
for key in keys:
kwarg_val = kwargs.pop(key, None)
Expand Down
8 changes: 0 additions & 8 deletions lib/matplotlib/cbook/deprecation.py

This file was deleted.

2 changes: 1 addition & 1 deletion lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ def __init__(self, segments, # Can be None.
if args:
argkw = {name: val for name, val in zip(argnames, args)}
kwargs.update(argkw)
cbook.warn_deprecated(
_api.warn_deprecated(
"3.4", message="Since %(since)s, passing LineCollection "
"arguments other than the first, 'segments', as positional "
"arguments is deprecated, and they will become keyword-only "
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import matplotlib
import matplotlib as mpl
from matplotlib.testing.decorators import (
image_comparison, check_figures_equal, remove_ticks_and_titles)
from matplotlib import rc_context
from matplotlib._api import MatplotlibDeprecationWarning
import matplotlib.colors as mcolors
import matplotlib.dates as mdates
from matplotlib.figure import Figure
Expand All @@ -32,8 +32,8 @@
import matplotlib.transforms as mtransforms
from numpy.testing import (
assert_allclose, assert_array_equal, assert_array_almost_equal)
from matplotlib import rc_context
from matplotlib.cbook import MatplotlibDeprecationWarning
from matplotlib.testing.decorators import (
image_comparison, check_figures_equal, remove_ticks_and_titles)

# Note: Some test cases are run twice: once normally and once with labeled data
# These two must be defined in the same test function or need to have
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest

from matplotlib import cbook, patheffects
from matplotlib.cbook import MatplotlibDeprecationWarning
from matplotlib._api import MatplotlibDeprecationWarning
from matplotlib.figure import Figure
from matplotlib.testing.decorators import check_figures_equal, image_comparison
import matplotlib as mpl
Expand Down
12 changes: 5 additions & 7 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@

from numpy.testing import assert_array_equal, assert_array_almost_equal

from matplotlib import cycler
from matplotlib import _api, cbook, cm, cycler
import matplotlib
import matplotlib.colors as mcolors
import matplotlib.cm as cm
import matplotlib.colorbar as mcolorbar
import matplotlib.cbook as cbook
import matplotlib.pyplot as plt
import matplotlib.scale as mscale
from matplotlib.testing.decorators import image_comparison, check_figures_equal
Expand Down Expand Up @@ -109,7 +107,7 @@ def test_colormap_global_set_warn():
new_cm = plt.get_cmap('viridis')
# Store the old value so we don't override the state later on.
orig_cmap = copy.copy(new_cm)
with pytest.warns(cbook.MatplotlibDeprecationWarning,
with pytest.warns(_api.MatplotlibDeprecationWarning,
match="You are modifying the state of a globally"):
# This should warn now because we've modified the global state
new_cm.set_under('k')
Expand All @@ -120,7 +118,7 @@ def test_colormap_global_set_warn():
# Test that registering and then modifying warns
plt.register_cmap(name='test_cm', cmap=copy.copy(orig_cmap))
new_cm = plt.get_cmap('test_cm')
with pytest.warns(cbook.MatplotlibDeprecationWarning,
with pytest.warns(_api.MatplotlibDeprecationWarning,
match="You are modifying the state of a globally"):
# This should warn now because we've modified the global state
new_cm.set_under('k')
Expand All @@ -132,11 +130,11 @@ def test_colormap_global_set_warn():

def test_colormap_dict_deprecate():
# Make sure we warn on get and set access into cmap_d
with pytest.warns(cbook.MatplotlibDeprecationWarning,
with pytest.warns(_api.MatplotlibDeprecationWarning,
match="The global colormaps dictionary is no longer"):
cmap = plt.cm.cmap_d['viridis']

with pytest.warns(cbook.MatplotlibDeprecationWarning,
with pytest.warns(_api.MatplotlibDeprecationWarning,
match="The global colormaps dictionary is no longer"):
plt.cm.cmap_d['test'] = cmap

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import matplotlib as mpl
from matplotlib import pyplot as plt
from matplotlib.cbook import MatplotlibDeprecationWarning
from matplotlib._api import MatplotlibDeprecationWarning


def test_pyplot_up_to_date(tmpdir):
Expand Down