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

Skip to content

Commit b94a312

Browse files
authored
Merge pull request #12995 from anntzer/deprecationwarnings
Don't split creation of deprecation message and choice of warning class.
2 parents 0a9b5d0 + 780cb9a commit b94a312

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

lib/matplotlib/cbook/deprecation.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class MatplotlibDeprecationWarning(UserWarning):
1919
"""mplDeprecation is deprecated. Use MatplotlibDeprecationWarning instead."""
2020

2121

22-
def _generate_deprecation_message(
22+
def _generate_deprecation_warning(
2323
since, message='', name='', alternative='', pending=False,
2424
obj_type='attribute', addendum='', *, removal=''):
2525

@@ -34,7 +34,7 @@ def _generate_deprecation_message(
3434

3535
if not message:
3636
message = (
37-
"The %(name)s %(obj_type)s"
37+
"\nThe %(name)s %(obj_type)s"
3838
+ (" will be deprecated in a future version"
3939
if pending else
4040
(" was deprecated in Matplotlib %(since)s"
@@ -45,9 +45,12 @@ def _generate_deprecation_message(
4545
+ (" Use %(alternative)s instead." if alternative else "")
4646
+ (" %(addendum)s" if addendum else ""))
4747

48-
return message % dict(
48+
warning_cls = (PendingDeprecationWarning if pending
49+
else MatplotlibDeprecationWarning)
50+
51+
return warning_cls(message % dict(
4952
func=name, name=name, obj_type=obj_type, since=since, removal=removal,
50-
alternative=alternative, addendum=addendum)
53+
alternative=alternative, addendum=addendum))
5154

5255

5356
def warn_deprecated(
@@ -101,15 +104,12 @@ def warn_deprecated(
101104
# To warn of the deprecation of "matplotlib.name_of_module"
102105
warn_deprecated('1.4.0', name='matplotlib.name_of_module',
103106
obj_type='module')
104-
105107
"""
106-
message = '\n' + _generate_deprecation_message(
108+
warning = _generate_deprecation_warning(
107109
since, message, name, alternative, pending, obj_type, addendum,
108110
removal=removal)
109-
category = (PendingDeprecationWarning if pending
110-
else MatplotlibDeprecationWarning)
111111
from . import _warn_external
112-
_warn_external(message, category)
112+
_warn_external(warning)
113113

114114

115115
def deprecated(since, *, message='', name='', alternative='', pending=False,
@@ -203,19 +203,19 @@ class _deprecated_property(property):
203203
def __get__(self, instance, owner):
204204
if instance is not None:
205205
from . import _warn_external
206-
_warn_external(message, category)
206+
_warn_external(warning)
207207
return super().__get__(instance, owner)
208208

209209
def __set__(self, instance, value):
210210
if instance is not None:
211211
from . import _warn_external
212-
_warn_external(message, category)
212+
_warn_external(warning)
213213
return super().__set__(instance, value)
214214

215215
def __delete__(self, instance):
216216
if instance is not None:
217217
from . import _warn_external
218-
_warn_external(message, category)
218+
_warn_external(warning)
219219
return super().__delete__(instance)
220220

221221
def finalize(_, new_doc):
@@ -233,15 +233,13 @@ def finalize(wrapper, new_doc):
233233
wrapper.__doc__ = new_doc
234234
return wrapper
235235

236-
message = _generate_deprecation_message(
236+
warning = _generate_deprecation_warning(
237237
since, message, name, alternative, pending, obj_type, addendum,
238238
removal=removal)
239-
category = (PendingDeprecationWarning if pending
240-
else MatplotlibDeprecationWarning)
241239

242240
def wrapper(*args, **kwargs):
243241
from . import _warn_external
244-
_warn_external(message, category)
242+
_warn_external(warning)
245243
return func(*args, **kwargs)
246244

247245
old_doc = inspect.cleandoc(old_doc or '').strip('\n')

0 commit comments

Comments
 (0)