@@ -50,36 +50,41 @@ class MatplotlibDeprecationWarning(UserWarning):
50
50
51
51
def _generate_deprecation_message(since, message='', name='',
52
52
alternative='', pending=False,
53
- obj_type='attribute'):
53
+ obj_type='attribute',
54
+ addendum=''):
54
55
55
56
if not message:
56
- altmessage = ''
57
57
58
58
if pending:
59
59
message = (
60
- 'The %(func )s %(obj_type)s will be deprecated in a '
60
+ 'The %(name )s %(obj_type)s will be deprecated in a '
61
61
'future version.')
62
62
else:
63
63
message = (
64
- 'The %(func )s %(obj_type)s was deprecated in version '
64
+ 'The %(name )s %(obj_type)s was deprecated in version '
65
65
'%(since)s.')
66
- if alternative:
67
- altmessage = ' Use %s instead.' % alternative
68
66
69
- message = ((message % {
70
- 'func': name,
71
- 'name': name,
72
- 'alternative': alternative,
73
- 'obj_type': obj_type,
74
- 'since': since}) +
75
- altmessage)
67
+ altmessage = ''
68
+ if alternative:
69
+ altmessage = ' Use %s instead.' % alternative
70
+
71
+ message = ((message % {
72
+ 'func': name,
73
+ 'name': name,
74
+ 'alternative': alternative,
75
+ 'obj_type': obj_type,
76
+ 'since': since}) +
77
+ altmessage)
78
+
79
+ if addendum:
80
+ message += addendum
76
81
77
82
return message
78
83
79
84
80
85
def warn_deprecated(
81
86
since, message='', name='', alternative='', pending=False,
82
- obj_type='attribute'):
87
+ obj_type='attribute', addendum='' ):
83
88
"""
84
89
Used to display deprecation warning in a standard way.
85
90
@@ -90,7 +95,7 @@ def warn_deprecated(
90
95
91
96
message : str, optional
92
97
Override the default deprecation message. The format
93
- specifier `%(func )s` may be used for the name of the function,
98
+ specifier `%(name )s` may be used for the name of the function,
94
99
and `%(alternative)s` may be used in the deprecation message
95
100
to insert the name of an alternative to the deprecated
96
101
function. `%(obj_type)s` may be used to insert a friendly name
@@ -111,6 +116,9 @@ def warn_deprecated(
111
116
obj_type : str, optional
112
117
The object type being deprecated.
113
118
119
+ addendum : str, optional
120
+ Additional text appended directly to the final message.
121
+
114
122
Examples
115
123
--------
116
124
@@ -122,13 +130,13 @@ def warn_deprecated(
122
130
123
131
"""
124
132
message = _generate_deprecation_message(
125
- since, message, name, alternative, pending, obj_type)
133
+ since, message, name, alternative, pending, obj_type)
126
134
127
135
warnings.warn(message, mplDeprecation, stacklevel=1)
128
136
129
137
130
138
def deprecated(since, message='', name='', alternative='', pending=False,
131
- obj_type=None):
139
+ obj_type=None, addendum='' ):
132
140
"""
133
141
Decorator to mark a function or a class as deprecated.
134
142
@@ -140,15 +148,15 @@ def deprecated(since, message='', name='', alternative='', pending=False,
140
148
141
149
message : str, optional
142
150
Override the default deprecation message. The format
143
- specifier `%(func )s` may be used for the name of the function ,
151
+ specifier `%(name )s` may be used for the name of the object ,
144
152
and `%(alternative)s` may be used in the deprecation message
145
153
to insert the name of an alternative to the deprecated
146
- function . `%(obj_type)s` may be used to insert a friendly name
154
+ object . `%(obj_type)s` may be used to insert a friendly name
147
155
for the type of object being deprecated.
148
156
149
157
name : str, optional
150
- The name of the deprecated function ; if not provided the name
151
- is automatically determined from the passed in function ,
158
+ The name of the deprecated object ; if not provided the name
159
+ is automatically determined from the passed in object ,
152
160
though this is useful in the case of renamed functions, where
153
161
the new function is just assigned to the name of the
154
162
deprecated function. For example::
@@ -158,14 +166,17 @@ def new_function():
158
166
oldFunction = new_function
159
167
160
168
alternative : str, optional
161
- An alternative function that the user may use in place of the
162
- deprecated function . The deprecation warning will tell the user
169
+ An alternative object that the user may use in place of the
170
+ deprecated object . The deprecation warning will tell the user
163
171
about this alternative if provided.
164
172
165
173
pending : bool, optional
166
174
If True, uses a PendingDeprecationWarning instead of a
167
175
DeprecationWarning.
168
176
177
+ addendum : str, optional
178
+ Additional text appended directly to the final message.
179
+
169
180
Examples
170
181
--------
171
182
@@ -177,7 +188,7 @@ def the_function_to_deprecate():
177
188
178
189
"""
179
190
def deprecate(obj, message=message, name=name, alternative=alternative,
180
- pending=pending):
191
+ pending=pending, addendum=addendum ):
181
192
import textwrap
182
193
183
194
if not name:
@@ -212,7 +223,8 @@ def finalize(wrapper, new_doc):
212
223
return wrapper
213
224
214
225
message = _generate_deprecation_message(
215
- since, message, name, alternative, pending, obj_type)
226
+ since, message, name, alternative, pending,
227
+ obj_type, addendum)
216
228
217
229
def wrapper(*args, **kwargs):
218
230
warnings.warn(message, mplDeprecation, stacklevel=2)
0 commit comments