@@ -20,43 +20,35 @@ class MatplotlibDeprecationWarning(UserWarning):
2020mplDeprecation = MatplotlibDeprecationWarning
2121
2222
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 = '' ):
4226
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 )
5032
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 "" ))
5344
54- return message
45+ return message .format (func = name , name = name , obj_type = obj_type , since = since ,
46+ removal = removal , alternative = alternative )
5547
5648
5749def warn_deprecated (
5850 since , message = '' , name = '' , alternative = '' , pending = False ,
59- obj_type = 'attribute' , addendum = '' ):
51+ obj_type = 'attribute' , addendum = '' , * , removal = '' ):
6052 """
6153 Used to display deprecation warning in a standard way.
6254
@@ -85,6 +77,11 @@ def warn_deprecated(
8577 If True, uses a PendingDeprecationWarning instead of a
8678 DeprecationWarning.
8779
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+
8885 obj_type : str, optional
8986 The object type being deprecated.
9087
@@ -102,12 +99,12 @@ def warn_deprecated(
10299
103100 """
104101 message = _generate_deprecation_message (
105- since , message , name , alternative , pending , obj_type )
102+ since , message , name , alternative , pending , obj_type , removal = removal )
106103 warnings .warn (message , mplDeprecation , stacklevel = 2 )
107104
108105
109106def deprecated (since , message = '' , name = '' , alternative = '' , pending = False ,
110- obj_type = None , addendum = '' ):
107+ obj_type = None , addendum = '' , * , removal = '' ):
111108 """
112109 Decorator to mark a function or a class as deprecated.
113110
@@ -145,6 +142,11 @@ def new_function():
145142 If True, uses a PendingDeprecationWarning instead of a
146143 DeprecationWarning.
147144
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+
148150 addendum : str, optional
149151 Additional text appended directly to the final message.
150152
@@ -199,8 +201,8 @@ def finalize(wrapper, new_doc):
199201 return wrapper
200202
201203 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 )
204206
205207 def wrapper (* args , ** kwargs ):
206208 warnings .warn (message , mplDeprecation , stacklevel = 2 )
0 commit comments