Skip to content

Commit f21ad20

Browse files
committed
Use _warn_external for deprecations warnings.
We'll probably switch to _warn_external everywhere at some point, but in the meantime I think deprecations warnings are ones of those that benefit the most from warn_external ("oh, that's the place that needs to be fixed."). Note the internal import to workaround the circular import loop between cbook and cbook.deprecation.
1 parent ef04ad9 commit f21ad20

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

doc/users/dflt_style_changes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ a cleaner separation between subplots.
10021002
with mpl.rc_context(rc=rcparams):
10031003

10041004
ax = fig.add_subplot(2, 2, j)
1005-
ax.hist(np.random.beta(0.5, 0.5, 10000), 25, normed=True)
1005+
ax.hist(np.random.beta(0.5, 0.5, 10000), 25, density=True)
10061006
ax.set_xlim([0, 1])
10071007
ax.set_title(title)
10081008

lib/matplotlib/cbook/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,8 @@ def _warn_external(message, category=None):
19911991
frame = sys._getframe()
19921992
for stacklevel in itertools.count(1): # lgtm[py/unused-loop-variable]
19931993
if not re.match(r"\A(matplotlib|mpl_toolkits)(\Z|\.)",
1994-
frame.f_globals["__name__"]):
1994+
# Work around sphinx-gallery not setting __name__.
1995+
frame.f_globals.get("__name__", "")):
19951996
break
19961997
frame = frame.f_back
19971998
warnings.warn(message, category, stacklevel)

lib/matplotlib/cbook/deprecation.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def warn_deprecated(
109109
removal=removal)
110110
category = (PendingDeprecationWarning if pending
111111
else MatplotlibDeprecationWarning)
112-
warnings.warn(message, category, stacklevel=2)
112+
from . import _warn_external
113+
_warn_external(message, category)
113114

114115

115116
def deprecated(since, message='', name='', alternative='', pending=False,
@@ -216,7 +217,8 @@ def finalize(wrapper, new_doc):
216217
else MatplotlibDeprecationWarning)
217218

218219
def wrapper(*args, **kwargs):
219-
warnings.warn(message, category, stacklevel=2)
220+
from . import _warn_external
221+
_warn_external(message, category)
220222
return func(*args, **kwargs)
221223

222224
old_doc = textwrap.dedent(old_doc or '').strip('\n')

0 commit comments

Comments
 (0)