@@ -20,43 +20,35 @@ class MatplotlibDeprecationWarning(UserWarning):
20
20
mplDeprecation = MatplotlibDeprecationWarning
21
21
22
22
23
- def _generate_deprecation_message (since , message = '' , name = '' ,
24
- alternative = '' , pending = False ,
25
- obj_type = 'attribute' ,
26
- addendum = '' ):
27
-
28
- if not message :
29
-
30
- if pending :
31
- message = (
32
- 'The %(name)s %(obj_type)s will be deprecated in a '
33
- 'future version.' )
34
- else :
35
- message = (
36
- 'The %(name)s %(obj_type)s was deprecated in version '
37
- '%(since)s.' )
38
-
39
- altmessage = ''
40
- if alternative :
41
- altmessage = ' Use %s instead.' % alternative
23
+ def _generate_deprecation_message (
24
+ since , message = '' , name = '' , alternative = '' , pending = False ,
25
+ obj_type = 'attribute' , addendum = '' , * , removal = '' ):
42
26
43
- message = ((message % {
44
- 'func' : name ,
45
- 'name' : name ,
46
- 'alternative' : alternative ,
47
- 'obj_type' : obj_type ,
48
- 'since' : since }) +
49
- altmessage )
27
+ if removal == "" :
28
+ removal = {"2.2" : "in 3.1" , "3.0" : "in 3.2" }.get (
29
+ since , "two minor releases later" )
30
+ elif removal :
31
+ removal = "in {}" .format (removal )
50
32
51
- if addendum :
52
- message += addendum
33
+ if not message :
34
+ message = (
35
+ "The {name} {obj_type}"
36
+ + (" will be deprecated in a future version"
37
+ if pending else
38
+ (" was deprecated in Matplotlib {since}"
39
+ + (" and will be removed {removal}"
40
+ if removal else
41
+ "" )))
42
+ + "."
43
+ + (" Use {alternative} instead." if alternative else "" ))
53
44
54
- return message
45
+ return message .format (func = name , name = name , obj_type = obj_type , since = since ,
46
+ removal = removal , alternative = alternative )
55
47
56
48
57
49
def warn_deprecated (
58
50
since , message = '' , name = '' , alternative = '' , pending = False ,
59
- obj_type = 'attribute' , addendum = '' ):
51
+ obj_type = 'attribute' , addendum = '' , * , removal = '' ):
60
52
"""
61
53
Used to display deprecation warning in a standard way.
62
54
@@ -85,6 +77,11 @@ def warn_deprecated(
85
77
If True, uses a PendingDeprecationWarning instead of a
86
78
DeprecationWarning.
87
79
80
+ removal : str, optional
81
+ The expected removal version. With the default (an empty string), a
82
+ removal version is automatically computed from *since*. Set to other
83
+ Falsy values to not schedule a removal date.
84
+
88
85
obj_type : str, optional
89
86
The object type being deprecated.
90
87
@@ -102,12 +99,12 @@ def warn_deprecated(
102
99
103
100
"""
104
101
message = _generate_deprecation_message (
105
- since , message , name , alternative , pending , obj_type )
102
+ since , message , name , alternative , pending , obj_type , removal = removal )
106
103
warnings .warn (message , mplDeprecation , stacklevel = 2 )
107
104
108
105
109
106
def deprecated (since , message = '' , name = '' , alternative = '' , pending = False ,
110
- obj_type = None , addendum = '' ):
107
+ obj_type = None , addendum = '' , * , removal = '' ):
111
108
"""
112
109
Decorator to mark a function or a class as deprecated.
113
110
@@ -145,6 +142,11 @@ def new_function():
145
142
If True, uses a PendingDeprecationWarning instead of a
146
143
DeprecationWarning.
147
144
145
+ removal : str, optional
146
+ The expected removal version. With the default (an empty string), a
147
+ removal version is automatically computed from *since*. Set to other
148
+ Falsy values to not schedule a removal date.
149
+
148
150
addendum : str, optional
149
151
Additional text appended directly to the final message.
150
152
@@ -199,8 +201,8 @@ def finalize(wrapper, new_doc):
199
201
return wrapper
200
202
201
203
message = _generate_deprecation_message (
202
- since , message , name , alternative , pending ,
203
- obj_type , addendum )
204
+ since , message , name , alternative , pending , obj_type , addendum ,
205
+ removal = removal )
204
206
205
207
def wrapper (* args , ** kwargs ):
206
208
warnings .warn (message , mplDeprecation , stacklevel = 2 )
0 commit comments