Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 674d670

Browse files
authored
Merge pull request #20046 from brunobeltran/deprecation-warning
Deprecation warning
2 parents b33711b + 8c9af69 commit 674d670

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
``MatplotlibDeprecationWarning`` now subclasses ``DeprecationWarning``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Historically, it has not been possible to filter
4+
``MatplotlibDeprecationWarning``\s by checking for ``DeprecationWarning``,
5+
since we subclass ``UserWarning`` directly.
6+
7+
The decision to not subclass DeprecationWarning has to do with a decision from
8+
core Python in the 2.x days to not show DeprecationWarnings to users. However,
9+
there is now a more sophisticated filter in place (see
10+
https://www.python.org/dev/peps/pep-0565/).
11+
12+
Users will now see ``MatplotlibDeprecationWarning`` only during interactive
13+
sessions, and these can be silenced by the standard mechanism:
14+
15+
.. code:: python
16+
17+
warnings.filterwarnings("ignore", category=DeprecationWarning)
18+
19+
Library authors must now enable ``DeprecationWarning``\s explicitly in order
20+
for (non-interactive) CI/CD pipelines to report back these warnings, as is
21+
standard for the rest of the Python ecosystem:
22+
23+
.. code:: python
24+
25+
warnings.filterwarnings("always", DeprecationWarning)

doc/conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import warnings
1818

1919
import matplotlib
20-
from matplotlib._api import MatplotlibDeprecationWarning
2120
import sphinx
2221

2322
from datetime import datetime
@@ -117,7 +116,7 @@ def _check_dependencies():
117116

118117
# we should ignore warnings coming from importing deprecated modules for
119118
# autodoc purposes, as this will disappear automatically when they are removed
120-
warnings.filterwarnings('ignore', category=MatplotlibDeprecationWarning,
119+
warnings.filterwarnings('ignore', category=DeprecationWarning,
121120
module='importlib', # used by sphinx.autodoc.importer
122121
message=r'(\n|.)*module was deprecated.*')
123122

@@ -126,7 +125,7 @@ def _check_dependencies():
126125

127126
# make sure to ignore warnings that stem from simply inspecting deprecated
128127
# class-level attributes
129-
warnings.filterwarnings('ignore', category=MatplotlibDeprecationWarning,
128+
warnings.filterwarnings('ignore', category=DeprecationWarning,
130129
module='sphinx.util.inspect')
131130

132131
# missing-references names matches sphinx>=3 behavior, so we can't be nitpicky

lib/matplotlib/_api/deprecation.py

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

1919

20-
class MatplotlibDeprecationWarning(UserWarning):
20+
class MatplotlibDeprecationWarning(DeprecationWarning):
2121
"""
2222
A class for issuing deprecation warnings for Matplotlib users.
2323

lib/matplotlib/tests/test_figure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
import matplotlib as mpl
1010
from matplotlib import cbook, rcParams
11+
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
1112
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1213
from matplotlib.axes import Axes
1314
from matplotlib.figure import Figure
1415
from matplotlib.ticker import AutoMinorLocator, FixedFormatter, ScalarFormatter
1516
import matplotlib.pyplot as plt
1617
import matplotlib.dates as mdates
1718
import matplotlib.gridspec as gridspec
18-
from matplotlib.cbook import MatplotlibDeprecationWarning
1919
import numpy as np
2020
import pytest
2121

@@ -150,7 +150,7 @@ def test_figure_legend():
150150
def test_gca():
151151
fig = plt.figure()
152152

153-
with pytest.warns(UserWarning):
153+
with pytest.warns(MatplotlibDeprecationWarning):
154154
# empty call to add_axes() will throw deprecation warning
155155
assert fig.add_axes() is None
156156

0 commit comments

Comments
 (0)