@@ -128,9 +128,9 @@ def warn_deprecated(
128
128
129
129
130
130
def deprecated (since , message = '' , name = '' , alternative = '' , pending = False ,
131
- obj_type = 'function' ):
131
+ obj_type = None ):
132
132
"""
133
- Decorator to mark a function as deprecated.
133
+ Decorator to mark a function or a class as deprecated.
134
134
135
135
Parameters
136
136
----------
@@ -176,33 +176,49 @@ def the_function_to_deprecate():
176
176
pass
177
177
178
178
"""
179
- def deprecate (func , message = message , name = name , alternative = alternative ,
179
+ def deprecate (obj , message = message , name = name , alternative = alternative ,
180
180
pending = pending ):
181
- import functools
182
181
import textwrap
183
182
184
- if isinstance (func , classmethod ):
185
- func = func .__func__
186
- is_classmethod = True
187
- else :
188
- is_classmethod = False
189
-
190
183
if not name :
191
- name = func .__name__
184
+ name = obj .__name__
185
+
186
+ if isinstance (obj , type ):
187
+ obj_type = "class"
188
+ old_doc = obj .__doc__
189
+ func = obj .__init__
190
+ def finalize (wrapper , new_doc ):
191
+ try :
192
+ obj .__doc__ = new_doc
193
+ except AttributeError :
194
+ pass # cls.__doc__ is not writeable on Py2.
195
+ obj .__init__ = wrapper
196
+ return obj
197
+ else :
198
+ obj_type = "function"
199
+ if isinstance (obj , classmethod ):
200
+ func = obj .__func__
201
+ old_doc = func .__doc__
202
+ def finalize (wrapper , new_doc ):
203
+ wrapper = functools .wraps (func )(wrapper )
204
+ wrapper .__doc__ = new_doc
205
+ return classmethod (wrapper )
206
+ else :
207
+ func = obj
208
+ old_doc = func .__doc__
209
+ def finalize (wrapper , new_doc ):
210
+ wrapper = functools .wraps (func )(wrapper )
211
+ wrapper .__doc__ = new_doc
212
+ return wrapper
192
213
193
214
message = _generate_deprecation_message (
194
215
since , message , name , alternative , pending , obj_type )
195
216
196
- @functools .wraps (func )
197
- def deprecated_func (* args , ** kwargs ):
217
+ def wrapper (* args , ** kwargs ):
198
218
warnings .warn (message , mplDeprecation , stacklevel = 2 )
199
-
200
219
return func (* args , ** kwargs )
201
220
202
- old_doc = deprecated_func .__doc__
203
- if not old_doc :
204
- old_doc = ''
205
- old_doc = textwrap .dedent (old_doc ).strip ('\n ' )
221
+ old_doc = textwrap .dedent (old_doc or '' ).strip ('\n ' )
206
222
message = message .strip ()
207
223
new_doc = (('\n .. deprecated:: %(since)s'
208
224
'\n %(message)s\n \n ' %
@@ -212,11 +228,7 @@ def deprecated_func(*args, **kwargs):
212
228
# docutils when the original docstring was blank.
213
229
new_doc += r'\ '
214
230
215
- deprecated_func .__doc__ = new_doc
216
-
217
- if is_classmethod :
218
- deprecated_func = classmethod (deprecated_func )
219
- return deprecated_func
231
+ return finalize (wrapper , new_doc )
220
232
221
233
return deprecate
222
234
@@ -249,6 +261,7 @@ def unicode_safe(s):
249
261
return s
250
262
251
263
264
+ @deprecated ('2.1' )
252
265
class converter (object ):
253
266
"""
254
267
Base class for handling string -> python type with support for
@@ -267,12 +280,14 @@ def is_missing(self, s):
267
280
return not s .strip () or s == self .missing
268
281
269
282
283
+ @deprecated ('2.1' )
270
284
class tostr (converter ):
271
285
"""convert to string or None"""
272
286
def __init__ (self , missing = 'Null' , missingval = '' ):
273
287
converter .__init__ (self , missing = missing , missingval = missingval )
274
288
275
289
290
+ @deprecated ('2.1' )
276
291
class todatetime (converter ):
277
292
"""convert to a datetime or None"""
278
293
def __init__ (self , fmt = '%Y-%m-%d' , missing = 'Null' , missingval = None ):
@@ -287,6 +302,7 @@ def __call__(self, s):
287
302
return datetime .datetime (* tup [:6 ])
288
303
289
304
305
+ @deprecated ('2.1' )
290
306
class todate (converter ):
291
307
"""convert to a date or None"""
292
308
def __init__ (self , fmt = '%Y-%m-%d' , missing = 'Null' , missingval = None ):
@@ -301,6 +317,7 @@ def __call__(self, s):
301
317
return datetime .date (* tup [:3 ])
302
318
303
319
320
+ @deprecated ('2.1' )
304
321
class tofloat (converter ):
305
322
"""convert to a float or None"""
306
323
def __init__ (self , missing = 'Null' , missingval = None ):
@@ -313,6 +330,7 @@ def __call__(self, s):
313
330
return float (s )
314
331
315
332
333
+ @deprecated ('2.1' )
316
334
class toint (converter ):
317
335
"""convert to an int or None"""
318
336
def __init__ (self , missing = 'Null' , missingval = None ):
@@ -656,6 +674,7 @@ def __repr__(self):
656
674
in keys ])
657
675
658
676
677
+ @deprecated ('2.1' )
659
678
def unique (x ):
660
679
"""Return a list of unique elements of *x*"""
661
680
return list (set (x ))
@@ -851,6 +870,7 @@ def flatten(seq, scalarp=is_scalar_or_string):
851
870
yield subitem
852
871
853
872
873
+ @deprecated ('2.1' , "sorted(..., key=itemgetter(...))" )
854
874
class Sorter (object ):
855
875
"""
856
876
Sort by attribute or item
@@ -899,6 +919,7 @@ def byAttribute(self, data, attributename, inplace=1):
899
919
__call__ = byItem
900
920
901
921
922
+ @deprecated ('2.1' )
902
923
class Xlator (dict ):
903
924
"""
904
925
All-in-one multiple-string-substitution class
@@ -931,6 +952,7 @@ def xlat(self, text):
931
952
return self ._make_regex ().sub (self , text )
<
F987
tr class="diff-line-row">932
953
933
954
955
+ @deprecated ('2.1' )
934
956
def soundex (name , len = 4 ):
935
957
""" soundex module conforming to Odell-Russell algorithm """
936
958
@@ -959,6 +981,7 @@ def soundex(name, len=4):
959
981
return (sndx + (len * '0' ))[:len ]
960
982
961
983
984
+ @deprecated ('2.1' )
962
985
class Null (object ):
963
986
""" Null objects always and reliably "do nothing." """
964
987
@@ -1028,6 +1051,7 @@ def __call__(self, path):
1028
1051
get_realpath_and_stat = GetRealpathAndStat ()
1029
1052
1030
1053
1054
+ @deprecated ('2.1' )
1031
1055
def dict_delall (d , keys ):
1032
1056
"""delete all of the *keys* from the :class:`dict` *d*"""
1033
1057
for key in keys :
@@ -1037,6 +1061,7 @@ def dict_delall(d, keys):
1037
1061
pass
1038
1062
1039
1063
1064
+ @deprecated ('2.1' )
1040
1065
class RingBuffer (object ):
1041
1066
""" class that implements a not-yet-full buffer """
1042
1067
def __init__ (self , size_max ):
@@ -1088,6 +1113,7 @@ def get_split_ind(seq, N):
1088
1113
return len (seq )
1089
1114
1090
1115
1116
+ @deprecated ('2.1' , alternative = 'textwrap.TextWrapper' )
1091
1117
def wrap (prefix , text , cols ):
1092
1118
"""wrap *text* with *prefix* at length *cols*"""
1093
1119
pad = ' ' * len (prefix .expandtabs ())
@@ -1202,6 +1228,7 @@ def get_recursive_filelist(args):
1202
1228
return [f for f in files if not os .path .islink (f )]
1203
1229
1204
1230
1231
+ @deprecated ('2.1' )
1205
1232
def pieces (seq , num = 2 ):
1206
1233
"""Break up the *seq* into *num* tuples"""
1207
1234
start = 0
@@ -1213,6 +1240,7 @@ def pieces(seq, num=2):
1213
1240
start += num
1214
1241
1215
1242
1243
+ @deprecated ('2.1' )
1216
1244
def exception_to_str (s = None ):
1217
1245
if six .PY3 :
1218
1246
sh = io .StringIO ()
@@ -1224,6 +1252,7 @@ def exception_to_str(s=None):
1224
1252
return sh .getvalue ()
1225
1253
1226
1254
1255
+ @deprecated ('2.1' )
1227
1256
def allequal (seq ):
1228
1257
"""
1229
1258
Return *True* if all elements of *seq* compare equal. If *seq* is
@@ -1239,6 +1268,7 @@ def allequal(seq):
1239
1268
return True
1240
1269
1241
1270
1271
+ @deprecated ('2.1' )
1242
1272
def alltrue (seq ):
1243
1273
"""
1244
1274
Return *True* if all elements of *seq* evaluate to *True*. If
@@ -1252,6 +1282,7 @@ def alltrue(seq):
1252
1282
return True
1253
1283
1254
1284
1285
+ @deprecated ('2.1' )
1255
1286
def onetrue (seq ):
1256
1287
"""
1257
1288
Return *True* if one element of *seq* is *True*. It *seq* is
@@ -1265,6 +1296,7 @@ def onetrue(seq):
1265
1296
return False
1266
1297
1267
1298
1299
+ @deprecated ('2.1' )
1268
1300
def allpairs (x ):
1269
1301
"""
1270
1302
return all possible pairs in sequence *x*
@@ -1391,6 +1423,7 @@ def remove(self, o):
1391
1423
self .push (thiso )
1392
1424
1393
1425
1426
+ @deprecated ('2.1' )
1394
1427
def finddir (o , match , case = False ):
1395
1428
"""
1396
1429
return all attributes of *o* which match string in match. if case
@@ -1405,6 +1438,7 @@ def finddir(o, match, case=False):
1405
1438
return [orig for name , orig in names if name .find (match ) >= 0 ]
1406
1439
1407
1440
1441
+ @deprecated ('2.1' )
1408
1442
def reverse_dict (d ):
1409
1443
"""reverse the dictionary -- may lose data if values are not unique!"""
1410
1444
return {v : k for k , v in six .iteritems (d )}
@@ -1476,6 +1510,7 @@ def safezip(*args):
1476
1510
return list (zip (* args ))
1477
1511
1478
1512
1513
+ @deprecated ('2.1' )
1479
1514
def issubclass_safe (x , klass ):
1480
1515
"""return issubclass(x, klass) and return False on a TypeError"""
1481
1516
@@ -1720,6 +1755,7 @@ def simple_linear_interpolation(a, steps):
1720
1755
return result
1721
1756
1722
1757
1758
+ @deprecated ('2.1' , alternative = 'shutil.rmtree' )
1723
1759
def recursive_remove (path ):
1724
1760
if os .path .isdir (path ):
1725
1761
for fname in (glob .glob (os .path .join (path , '*' )) +
@@ -2018,6 +2054,7 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
2018
2054
2019
2055
2020
2056
# FIXME I don't think this is used anywhere
2057
+ @deprecated ('2.1' )
2021
2058
def unmasked_index_ranges (mask , compressed = True ):
2022
2059
"""
2023
2060
Find index ranges where *mask* is *False*.
@@ -2071,7 +2108,7 @@ def unmasked_index_ranges(mask, compressed=True):
2071
2108
# The ls_mapper maps short codes for line style to their full name used by
2072
2109
# backends; the reverse mapper is for mapping full names to short ones.
2073
2110
ls_mapper = {'-' : 'solid' , '--' : 'dashed' , '-.' : 'dashdot' , ':' : 'dotted' }
2074
- ls_mapper_r = reverse_dict (ls_mapper )
2111
+ ls_mapper_r = { v : k for k , v in six . iteritems (ls_mapper )}
2075
2112
2076
2113
2077
2114
def align_iterators (func , * iterables ):
0 commit comments