@@ -97,6 +97,24 @@ def deprecate_kwarg(old_arg_name, new_arg_name, mapping=None, stacklevel=2):
97
97
FutureWarning: old='yes' is deprecated, use new=True instead
98
98
warnings.warn(msg, FutureWarning)
99
99
yes!
100
+
101
+
102
+ To raise a warning that a keyword will be removed entirely in the future
103
+
104
+ >>> @deprecate_kwarg(old_arg_name='cols', new_arg_name=None)
105
+ ... def f(cols='', another_param=''):
106
+ ... print(cols)
107
+ ...
108
+ >>> f(cols='should raise warning')
109
+ FutureWarning: the 'cols' keyword is deprecated and will be removed in a
110
+ future version please takes steps to stop use of 'cols'
111
+ should raise warning
112
+ >>> f(another_param='should not raise warning')
113
+ should not raise warning
114
+ >>> f(cols='should raise warning', another_param='')
115
+ FutureWarning: the 'cols' keyword is deprecated and will be removed in a
116
+ future version please takes steps to stop use of 'cols'
117
+ should raise warning
100
118
"""
101
119
102
120
if mapping is not None and not hasattr (mapping , 'get' ) and \
@@ -111,8 +129,8 @@ def wrapper(*args, **kwargs):
111
129
112
130
if new_arg_name is None and old_arg_value is not None :
113
131
msg = (
114
- "the '{old_name}' keyword is deprecated and will be"
115
- "removed in a future version"
132
+ "the '{old_name}' keyword is deprecated and will be "
133
+ "removed in a future version "
116
134
"please takes steps to stop use of '{old_name}'"
117
135
).format (old_name = old_arg_name )
118
136
warnings .warn (msg , FutureWarning , stacklevel = stacklevel )
0 commit comments